Script-wide validation
Enable stricter checks in a traditional script.
JS Puzzles · Const
Strict mode is enabled with the "use strict" directive at the top of a script or function. It changes JavaScript to a stricter execution mode; classes and modules enable it automatically.
Strict mode is enabled by placing the exact directive "use strict" at the beginning of a script or function. A script-level directive affects the whole script, while a function-level directive affects only that function. Classes and modules enable strict mode automatically.
"use strict";'use strict';
function assignUndeclared() {
undeclared = 1;
}
try {
assignUndeclared();
} catch (error) {
console.log(error instanceof ReferenceError);
}The strict function throws instead of silently creating a global variable.
Enable stricter checks in a traditional script.
Constrain legacy code to a stricter function body.
Use classes or modules without adding a directive.
classesmodulesscriptsfunctions