Strict Mode
EasyIn plain terms
Strict mode makes JavaScript throw errors for common mistakes like using undeclared variables. Add "use strict" at the top of a file or function. Modern modules are strict by default.
What you need to know
- •Prevents undeclared variables
- •Disallows duplicate parameter names
- •Modules and classes are strict by default
Try it yourself
Copy the code below and run it in your browser console or a code editor:
'use strict';
x = 10; // Error! x is not defined
function foo() {
'use strict';
y = 5; // Error in strict mode
}
// Deleting variables not allowed
let z = 1;
// delete z; // Error in strict modeLearn more
Dive deeper with these trusted resources: