This site is mobile accessible. Press the "Tap Here" button to use a different font-size.
Smartphone icons created by Freepik - Flaticon
Defines that JavaScript code should be executed in "strict mode".
Directive | |||||
---|---|---|---|---|---|
"use strict" | 13.0 | 10.0 | 4.0 | 6.0 | 12.1 |
"use strict"; x = 3.14; // This will cause an error because x is not declared
"use strict"; myFunction(); function myFunction() { y = 3.14; // This will also cause an error because y is not declared }
Declared inside a function, it has local scope (only the code inside the function is in strict mode):
x = 3.14; // This will not cause an error. myFunction(); function myFunction() { "use strict"; y = 3.14; // This will cause an error }
Using a variable, without declaring it, is not allowed:
"use strict"; x = 3.14; // This will cause an error
"use strict"; x = {p1:10, p2:20}; // This will cause an error
Deleting a variable (or object) is not allowed.
"use strict"; var x = 3.14; delete x; // This will cause an error
Deleting a function is not allowed.
"use strict"; function x(p1, p2) {}; delete x; // This will cause an error
Duplicating a parameter name is not allowed:
"use strict"; function x(p1, p1) {}; // This will cause an error
Octal numeric literals are not allowed:
"use strict"; var x = 010; // This will cause an error
Octal escape characters are not allowed:
"use strict"; var x = "\010"; // This will cause an error
Writing to a read-only property is not allowed:
"use strict"; var obj = {}; Object.defineProperty(obj, "x", {value:0, writable:false}); obj.x = 3.14; // This will cause an error
Writing to a get-only property is not allowed:
"use strict"; var obj = {get x() {return 0} }; obj.x = 3.14; // This will cause an error
Deleting an undeletable property is not allowed:
"use strict"; delete Object.prototype; // This will cause an error
The word
cannot be used as a variable:"use strict"; var eval = 3.14; // This will cause an error
The word
cannot be used as a variable:"use strict"; var arguments = 3.14; // This will cause an error
The
statement is not allowed:"use strict"; with (Math){x = cos(2)}; // This will cause an error
For security reasons,
is not allowed to create variables in the scope from which it was called:"use strict"; eval ("var x = 2"); alert (x); // This will cause an error
"use strict"; function myFunction() { alert(this); // will alert "undefined" } myFunction();
"use strict"; var public = 1500; // This will cause an error
Eventually the navigation links, above, will be replaced by these (previous) and (next) buttons below.
JavaScript icons used in the buttons provided by ICONS8.COM. Smartphone icons created by Freepik - Flaticon