In JavaScript, the “strict mode” is a way to opt in to a restricted variant of JavaScript. Strict mode makes it easier to write “secure” JavaScript.
You can enable strict mode for an entire script by including the following line at the top of your script:
"use strict";
You can also enable strict mode for a specific function by including the line inside the function:
function myFunction() {
"use strict";
// code here
}
When strict mode is in effect, it catches common coding mistakes and “unsafe” actions, and throws an error when such actions are encountered. For example:
- Strict mode disallows using a variable without declaring it first with
var
,let
, orconst
. - Strict mode disallows using a property of an object that has not yet been declared.
- Strict mode disallows using
with
statements.
In short, strict mode helps you write more secure and reliable JavaScript code. It’s a good practice to use strict mode in your scripts and functions.
+ There are no comments
Add yours