JavaScript: Strict Mode support in Browsers and Backward Compatibility

Strict Mode was introduced in ECMAScript 5.0 and is intended to make programs simpler and free of errors. In strict mode, a more rigid set of syntax checks is used to either catch an undeclared variable or any other errors in your code. Strict mode changes semantics!

What is ECMAScript?

ECMAScript was initiated by a European Standards Body called ECMA to create a formal standard for the JavaScript language. JavaScript is based on the ECMAScript standard (ES). The latest version is based on ECMAScript standard 262 when version 5.0 was approved in December 2009.

There are a number of keywords reserved by JavaScript but here are some reserved when using the ‘strict mode’ - implements, interface, let, package, private, protected, public, static, yield. Apart from these, you cannot use arguments and eval as functions or parameters names. There are many other changes that have been documented here

What if my browser, especially older versions, does not support Strict Mode?

StrictMode is declared as a string. For eg:

Globally as "use strict";

and in a function as

function someFunction(){
"use strict";
// code from DevCurry.com 
}


Since the Strict mode is declared as a string, it is backward compatible. Older browsers simply ignore it, without raising any errors. However you should make sure to test your code in browsers that do and do not support strict mode. 

Which browsers support Strict Mode?

As of this writing IE 10 (Preview 1), Firefox 4 & 5, Chrome 12, Webkit, Besen and Jurassic support Strict Mode. It’s here to stay, so get used to it!





About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: