Hint
Opt-in to stricter parsing — catches silent errors, changes some behaviors
Strict mode activates a restricted variant of JavaScript that converts silent errors into thrown errors and disables some confusing/dangerous features.
What it prevents:
x = 5 throws ReferenceError (not window.x)function fn(a, a) {} throwsthis in standalone functions is undefined (not window)delete on variables/functions — throws0777) — throws'use strict';
x = 5; // ReferenceError — no more accidental globals
function fn(a, a) {} // SyntaxError
function test() {
console.log(this); // undefined (not window)
}
test();
Good news: ES6 modules and classes are always in strict mode automatically. In modern code you rarely need to write 'use strict' explicitly.