Skip to main content

JavaScript Strict Mode

JavaScript introduced strict mode in ES5. Strict mode can be applied by writing 'use strict'.

Strict mode can be applied to entire script by putting "use strict" before any other statement.

To invoke strict mode to a specific function, put it in function's body before any other statement.

JavaScript modules are automatically in strict mode.

use of strict mode

  • Eliminates some JavaScript silent errors by changing them to throw errors.
  • Fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.
  • Prohibits some syntax likely to be defined in future versions of ECMAScript.