Coding For a Living

rss

A place to share and comment about coding for a living.


Visual Studio 2012– JavaScript Strict Mode Mike McIntyre

Visual Studio 2012’s JavaScript Strict Mode provides better error checking.

Strict Mode

Strict mode is a way to introduce better error-checking into your code. When you use strict mode, you cannot, for example, use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible.

For example, in the following example all the code is in strict mode, and the variable declaration outside the function causes the syntax error "Variable undefined in strict mode."

"use strict"; function testFunction(){ var testvar = 4; return testvar; } testvar = 5;
"use strict"; function testFunction(){ var testvar = 4; return testvar; } testvar = 5;