What does 'use strict' do?
By FrontendPro Editorial Team Updated 9/26/2026
Answer
It opts into a stricter variant of JavaScript that turns silent mistakes into errors and removes a few legacy behaviours.
"use strict"; // whole file — must be the first statement
function f() {
"use strict"; // or just this function
}
What changes
- Undeclared variables throw.
x = 5without a declaration is aReferenceErrorinstead of silently creating a global — the single most useful change. - Silent failures become errors. Assigning to a read-only or frozen property, or to a getter-only accessor, throws instead of doing nothing.
thisisundefinedin a plain function call, rather than the global object. This is what makes forgettingnewfail loudly.- Duplicate parameter names are a syntax error.
deleteon a variable is a syntax error.- Octal literals like
010are rejected. withis banned, andevalcannot introduce variables into the surrounding scope.- Some words are reserved for future use:
implements,interface,private,public,static,yield.
You are probably already in it
ES modules and class bodies are always strict, with no directive needed. Any file with import or export, and anything inside a class, already runs this way. That is why most modern code never writes the directive — and why behaviour differs when you copy a snippet from a module into a plain <script>.
Why it exists
JavaScript could not fix its early mistakes without breaking the web, so strict mode was added as an opt-in. Newer features simply made it the default.
One practical note
Bundlers can concatenate files, so a directive at the top of one file could once affect others. That is why the function-level form exists, and why relying on file-level directives in a bundle is fragile. With modules, the question does not arise.
