Douglas Crockford has written a nice post on the strict mode (source: Matthias Hölzl). The following is a summary of it.
What it is
- Strict mode is part of the ECMAScript 5 standard.
- You can enable strict mode for a complete file or a single function:
- Single function: using the mode for a complete file might break some functions in it, so by putting the line mentioned above at the beginning of a function, you can enable strict mode for it.
- Safety is one of the main motivations for strict mode (see end of Crockford’s post)
Most important changes
- Improved safety: very limited use of eval(), with statement not permitted.
- Global variables must be explicitly declared (no more auto-creation). This helps to prevent typos.
- Calling constructor functions without new: Prior to strict mode, this was bound to the global object which resulted in properties being added to that object. In strict mode, this will be bound to undefined and an exception will usually be thrown if constructors are called without new.
- Noisy failure: Attempting to change a read-only property throws an exception. So does attempting to delete a non-configurable property.
- Arguments object: The properties arguments.callee and arguments.caller have been eliminated (for safety reasons: it keeps them secret from foreign code).
- Function parameters: No more duplicate parameter names or variables that have the same name as a parameter.