According to this article
Adding “use strict” as the first statement¹ in your JavaScript code will enforce Strict Mode over the entire
So why :
"use strict";
012;
Doesn't throw errors
while
(function () {
"use strict";
012; })();
does ? (Octal literals are not allowed in strict mode.)
John resig says nothing about it. he just says :
Simple. Toss this at the top of a program to enable it for the whole script:
"use strict"; Or place it within a function to turn on strict mode only within that context.
function imStrict(){ "use strict"; // ... your code ... }
edit :
edit #2.
I tested the code in console.(chrome). in jsbin sample - it is working. still , I dont understand why it behave different in console.
"use strict"; 012;
in one line?"use strict"
.foo="bar"
(no declaration). This is not the case for application code, where it actually counts. Additionally, there are usually methods define in the console that are not available in application code. Bottom line... if you see odd behavior in the console, first verify in an actual application.