Strict Mode in JavaScript

From the JavaScript cheat sheet · Hoisting & Strict Mode · verified Jul 2026

Strict Mode

Using strict mode for safer JavaScript

javascript
// Enable strict mode
'use strict';

// Prevents accidental globals
// mistypedVariable = 17; // Error

// Prevents duplicate parameters
// function sum(a, a, c) {} // Error

// Makes eval safer
// eval has its own scope in strict mode
💡 Always use strict mode to catch common mistakes
⚡ Modules and classes are automatically in strict mode
📌 Strict mode must be first statement in script or function
🔥 Strict mode makes this undefined in regular functions

More JavaScript tasks

Back to the full JavaScript cheat sheet