我想在Chrome控制檯中使用嚴格模式根據我讀這兩種方法應該工作,但只有方法1工作。在方法2中我做錯了一些事情,或者不可能使用像這樣的嚴格模式。嚴格模式在鉻控制檯不工作
方法1:
(function f(){
'use strict';
function fn(text){herd=text; console.log(herd);}
fn("Hi Welcome");
})();
方法1
的輸出VM1139:3 Uncaught ReferenceError: herd is not defined
at fn (<anonymous>:3:23)
at f (<anonymous>:4:1)
at <anonymous>:5:3
方法2:
'use strict';
function fnete(text) {as=text; console.log(as);}
'use strict'; fnete("hi");
方法2
hi
的輸出
在Chrome 57它不工作 – Naveen
對我來說,鉻57拋出一個'VM1721:2未捕獲的ReferenceError:如未定義「錯誤。但爲什麼你要確保控制檯中的嚴格模式呢? –
我正在學習嚴格模式。 – Naveen