What is the purpose of 'use strict' directive?

The story behind the answer

The 'use strict' directive enables strict mode for the JavaScript code in its surrounding script or function. Strict mode applies tighter rules and turns several historically silent mistakes into early errors or runtime errors.

For example, assigning to an undeclared variable is not allowed in strict mode, and attempts to delete certain non-configurable properties fail. Strict mode also changes the value of this in a plain function call: instead of being substituted with the global object, it remains undefined. These rules help expose bugs and make code behavior more predictable.

The directive is a string literal placed at the beginning of a script or function body. It does not enable ES6 features, impose static type checking, or remove the need for semicolons. JavaScript modules and class bodies are strict automatically, so they generally do not need an explicit directive.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: