What is Strict Mode in JavaScript ?

Strict mode prevents certain actions and throws more exceptions. The statement “use strict” orders browser to use the Strict mode, which is a reduced and safer feature set of JavaScript. Strict mode eliminates some silent errors in JavaScript by changing them to throw errors.

Strict mode resolves mistakes that make it difficult for JavaScript engines to perform optimizations hence strict mode code can sometimes run faster than identical code that’s not strict mode. Strict mode forbids some syntax likely to be defined in future versions of ECMAScript. It prevents, or throws errors, when unsafe actions are taken (such as gaining access to the global object).

It disables features that are confusing or poorly thought out. Due to Strict mode it becomes easier to write secure JavaScript. Strict mode applies to individual functions or to entire scripts. It doesn't apply to block statements enclosed in {} braces; attempting to apply it to such contexts does nothing.

To invoke strict mode for an entire script, put statement "use strict" before any other statements. To invoke strict mode for a function, put statement "use strict" in the function's body before any other statements.



You May Interest

JavaScript Making Lowercase

What are Important Events in Javascript ?

What are Deferred Scripts in Javascript ?

What is setInterval Function in Javascript ?

What are the Variable Naming Conventions in JavaScript ?