Strictmode in JavaScript imposes several restrictions on the usage of reserved keywords and variable names to help developers write cleaner and more reliable code. Here are some of the key restrictions imposed by strict mode:
Reserved Keywords as Variables:
In strict mode, using reserved keywords (e.g., let,
class, function) as variable names is not allowed.
"use strict";
let let = 10; // Error: Unexpected keyword 'let'
Reserved Keywords as Function Parameters:
You cannot use reserved keywords as function parameter names.
In strict mode, you cannot assign values to arguments or
eval or use them as variable names.
"use strict";
eval = 10; // Error: Assignment to a reserved variable name 'eval'
var arguments = 42; // Error: Assignment to a reserved variable name 'arguments'
Octal Numeric Literals:
Octal literals (e.g., numbers with leading zeros like 0123) are not allowed in strict mode.
"use strict";
const octalNumber = 0123; // Error: Octal literals are not allowed in strict mode
Duplicate Parameter Names:
Strict mode prohibits duplicate parameter names in function declarations.
"use strict";
function duplicateParam(x, x) { // Error: Duplicate parameter name not allowed in this context
// ...
}
Global Object this:
In strict mode, the global object (this) inside a function called in the global context is
undefined, rather than referring to the global object itself (e.g.,
window in browsers).
In strict mode, assigning a value to an undeclared variable (one that hasn't been declared with
var, let, or const) is not allowed.
"use strict";
undeclaredVar = 42; // Error: Assignment to an undeclared variable
Strict mode helps catch common coding mistakes and promotes better coding practices by making JavaScript more strict and less forgiving of certain types of errors. It's recommended to use strict mode in your JavaScript code to ensure cleaner, safer, and more predictable behavior. You can enable strict mode globally by including
"use strict"; at the beginning of your script or function.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Strict mode in JavaScript imposes several restrictions on the usage of reserved keywords and variable names to help developers write cleaner and more reliable code. Here are some of the key restrictions imposed by strict mode:
Reserved Keywords as Variables:
Reserved Keywords as Function Parameters:
Reserved Keywords as Property Names:
arguments and eval:
Octal Numeric Literals:
Duplicate Parameter Names:
Global Object this:
Assignment to Undeclared Variables:
Strict mode helps catch common coding mistakes and promotes better coding practices by making JavaScript more strict and less forgiving of certain types of errors. It's recommended to use strict mode in your JavaScript code to ensure cleaner, safer, and more predictable behavior. You can enable strict mode globally by including "use strict"; at the beginning of your script or function.