JavaScript's strict mode is a way to opt in
to a restricted variant of JavaScript. Strict mode code and non-strict mode code can coexist, so scripts can opt into strict mode incrementally
Strict mode makes several changes to normal JavaScript semantics:
(function(){
"use strict";
// do you code
})();
Simply write "use strict"
this at the top of a program to enable it for the whole script. You can also use it with in a function like the following
function strictModeMethod( someVariable ){
"use strict";
someVariable = 1;
console.log( someVariable); // 1
console.log( arguments[0] ); // here
}
strictModeMethod("here")
someVariable = "test"
// errorNaN = 5;
// error function test2(arg) {
"use strict";
delete arg; // throughs an error
}
4. Defining a property more than once in an object literal will cause an exception to be throw an
{ foo: true, foo: false } // error
5. functions parameter names must be unique
fun(x,x) // error
6. Strict mode does not alias properties of the arguments object with the formal parameter
(function(test){
"use strict";
test = 56
console.log (test); // 56
console.log(arguments[0]) // test ouyput
})();
7. arguments.callee
does not suppoerted by strict mode.