//變量 要聲明 /*"use strict"; a='liuynag'; console.log(a);//Uncaught ReferenceError: a is not defined*///不能調用delete // "use strict"; /*var color='red'; console.log(color); delete color;//Delete of an unqualified identifier in strict mode. console.log(color);*///不能將保留字作為變量名 /* "use strict"; var public='hah'; console.log(public);//Unexpected strict mode reserved Word*///嚴格模式 對象重名屬性報錯 /*"use strict"; var person={ name:'hahhha', name:'greg' } console.log(person.name);//編輯器報錯,瀏覽器沒有*///重名參數 /*"use strict"; function a(num,num){ console.log(num);// Duplicate parameter name not allowed in this context console.log(arguments[1]); console.log(a.length); } a(11,12);*///arguments對象 // "use strict"; /*function a(num,num1){ num=2; console.log(arguments[0]);//嚴格11 不嚴格 2 } a(11,12);*///淘汰了arguments.callee arguments.caller // "use strict" /*function factorial(num){ if(num<=1){ return 1; }else{ return num*arguments.callee(num-1); } } console.log(factorial(5));//'caller', 'callee', and 'arguments' PRoperties may not be accessed on strict mode functions or the arguments objects for calls to them*///嚴格模式下 if語句不能創建函數 預編譯不會提到if語句外 /*"use strict" if(true){ function dosomething(){ console.log("好像沒出錯"); } }else{ //寫完 } dosomething();//ReferenceError: dosomething is not defined*///eval(),它將不再包含上下文中創建函數或者變量; /*"use strict" function dosomething(){ eval("var x=10"); console.log(x);//: x is not defined } dosomething()*///eval()在嚴格模式下只有在被求值的特殊作用域下有效,隨后被銷毀 /*"use strict" var result=eval("var x=10,y=11;x+y"); alert(result);//21*///抑制this /*"use strict" var color='red'; function color1(){ console.log(this.color); } color1(null);//嚴格Cannot read property 'color' of undefined 不嚴格 red*///拋棄了with語句 /*"use strict" with(location){ alert(href);////嚴格Strict mode code may not include a with statement不嚴格 一段地址 }*///拋棄8進制,0開頭不屬于8進制 /*"use strict"; var value='010'; console.log(parseInt(value));//不嚴格8 嚴格10*/