ECMAScript 5 introduced the concept of "strict mode" . It allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions . Its main purpose is to do more checking.
How 'strict mode'
The following script will work because it is non strict mode.
The following script won't work because it is in strict mode.
The above script will throw a reference error because variable str is used without declaring it.
So, how to correct it?
The major browsers now implement strict mode. However, don't blindly depend on it since there still are numerous Browser versions used in the wild that only have partial support for strict mode or do not support it at all (e.g. Internet Explorer below version 10!). Strict mode changes semantics. Relying on those changes will cause mistakes and errors in browsers which don't implement strict mode
What happens if browsers doesn't support Strict Mode?
Advantage of using strict mode:
- Make code run faster sometime than identical code that's not in strict mode.
- Prohibits some syntax likely to be defined in future version of ECMAScript.
- What is noscript tag?
- Difference between '=', '==' and '===' operators?
- What is Browser Object Model
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What's the Difference Between Class and Prototypal Inheritance?
- Event bubbling and Event Capturing in JavScript?