Skip to content

Strict Mode

In one line

Strict mode is an opt-in mode that makes JavaScript stricter, catching common mistakes as errors instead of silent failures.

In simple words

Strict mode ('use strict') is a way to opt into a restricted variant of JavaScript that eliminates some silent errors, fixes mistakes that make optimization difficult, and prohibits some unsafe syntax.

In strict mode: assigning to undeclared variables throws an error (instead of creating a global), this is undefined in regular functions (instead of the global object), duplicate parameter names are not allowed, and deleting non-deletable properties throws.

To enable strict mode for a whole file, put 'use strict'; at the top. For a single function, put it inside the function body. ES modules and class bodies are always in strict mode automatically. Using strict mode is recommended for all new code.

Example

javascript
"use strict";
undeclaredVar = 10; // ReferenceError

function fn() {
  "use strict";
  return this; // undefined (not global)
}

Strict mode catches undeclared variables and changes this behavior.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary