Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

'use strict'

Enables strict mode: errors that used to be silent become explicit.

Available since: ES5

Syntax

'use strict';

Examples

Assigning an undeclared variable is an error:

'use strict';
 
try {
  undeclared = 5;
} catch (error) {
  console.log(error.name);
}

Output:

ReferenceError

Notes

The string must come first in a file or function. Modules (import/export) and classes are always strict, so modern code rarely needs it.

See also

  • Object.freeze — Prevents any changes to an object.
  • var — The legacy way to declare a variable.

In the tutorial

  • Strict mode — The use strict directive in JavaScript: which mistakes strict mode catches, this in functions, forbidden syntax and where strict mode is turned on automatically.

Thanks for reading!

Donate to the site — we work hard for you.