The purpose of "use strict" is to indicate that the code should be executed in "strict mode".
With strict mode, you can not, for example, use undeclared variables.
|Strict mode is supported in:
Internet Explorer from version 10. Firefox from version 4.
Chrome from version 13. Safari from version 5.1. Opera from version 12.
Declared inside a function, it has local scope (only the code inside the function is in strict mode).
So "use strict"; only matters to new compilers that "understand" the meaning of it.
Strict mode changes previously accepted "bad syntax" into real errors.
In strict mode, any assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object, will throw an error.
Using a variable (property or object) without declaring it, is not allowed:
Deleting a variable, a function, or an argument, is not allowed.
Defining a property more than once, is not allowed:
Duplicating a parameter name is not allowed:
Octal numeric literals and escape characters are not allowed:
Writing to a read-only property is not allowed:
Writing to a get-only property is not allowed:
Deleting an undeletable property is not allowed:
The string "eval" cannot be used as a variable:
The string "arguments" cannot be used as a variable:
The with statement is not allowed:
For security reasons, eval() is not allowed to create variables in the scope from which it was called:
In function calls like f(), the this value was the global object. In strict mode, it is now undefined.
Future reserved keywords are not allowed. These are:
|The "use strict" directive is only recognized at the beginning of a script or a function.|