STRICT uses cases

this fiddle has advantages what strict mode brings in

by bhupendra negi

JavaScript

"use strict"


// this will not work in strict mode , as code is ambigous , href does not if its in location objcet or in global scope variable
with(location)
{
 alert(href);   
}

// global variable access, if global varibale no defined then assignement to that global variable will result in error

test = "js strict test ";
alert(test);

// without new operator , error in strict mode
function Person(name) {
    this.name = name;
}

var personobj = new Person("shyam");

// dublicaets avioided , throws error
var object = {
    name: "abc",
    name: "xyz"

}

// eval as undergone changes , variable declared inside eval , remain in dat scope only .

( function testneweval()
{
    "use strict"
   var result= eval('var x = 10; var y =20; x+y');
    alert(x); // not works in strict mode
    alert(result);
    
}());