JavaScript 'use strict' Statement
The 'use strict' directive turns on strict mode, which turns some silent mistakes into errors and disables a few problematic features. Modules and classes are always strict.
Description
The 'use strict' directive, placed at the start of a script or function, enables strict mode. In strict mode, assigning to an undeclared variable throws a ReferenceError instead of creating a global, writing to read-only properties throws, this is undefined in plain function calls rather than the global object, duplicate parameter names are errors, and the with statement is forbidden.
JavaScript modules and the bodies of classes are always in strict mode, so modern code usually gets it automatically.
You can also enable strict mode for a single function by putting the directive at the start of its body, which was useful when mixing old and new code. The directive must be the first statement; anywhere else it's just an ordinary string with no effect. Strict mode code can also be faster in some engines, because it removes features that make optimization difficult, such as the with statement.
Syntax
'use strict';Example
Browser Support
The following information will show you the current browser support for the 'use strict' statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





