Favorites

JavaScript 'use strict' Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
'use strict'
JavaScript OtherThis statement is supported by all modern browsers.
Updated 28th November 2026

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

'use strict';
try {
  undeclared = 5;
} catch (e) {
  console.log(e.name, e.message);
}
function whoAmI() { return this; }
console.log(whoAmI());

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.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee