Tutorial by Examples

Strict mode can be applied on entire scripts by placing the statement "use strict"; before any other statements. "use strict"; // strict mode now applies for the rest of the script Strict mode is only enabled in scripts where you define "use strict". You can combin...
Strict mode can also be applied to single functions by prepending the "use strict"; statement at the beginning of the function declaration. function strict() { "use strict"; // strict mode now applies to the rest of this function var innerFunction = function () { ...
In a non-strict-mode scope, when a variable is assigned without being initialized with the var, const or the let keyword, it is automatically declared in the global scope: a = 12; console.log(a); // 12 In strict mode however, any access to an undeclared variable will throw a reference error: &...
Strict mode also prevents you from deleting undeletable properties. "use strict"; delete Object.prototype; // throws a TypeError The above statement would simply be ignored if you don't use strict mode, however now you know why it does not execute as expected. It also prevents you fr...
arguments object behave different in strict and non strict mode. In non-strict mode, the argument object will reflect the changes in the value of the parameters which are present, however in strict mode any changes to the value of the parameter will not be reflected in the argument object. function...
Strict mode does not allow you to use duplicate function parameter names. function foo(bar, bar) {} // No error. bar is set to the final argument when called "use strict"; function foo(bar, bar) {}; // SyntaxError: duplicate formal argument bar
In Strict Mode, functions declared in a local block are inaccessible outside the block. "use strict"; { f(); // 'hi' function f() {console.log('hi');} } f(); // ReferenceError: f is not defined Scope-wise, function declarations in Strict Mode have the same kind of binding as l...
function a(x = 5) { "use strict"; } is invalid JavaScript and will throw a SyntaxError because you cannot use the directive "use strict" in a function with Non-Simple Parameter list like the one above - default assignment x = 5 Non-Simple parameters include - Default a...

Page 1 of 1