What Is It?
It is not a statement, but a literal expression that defines that JavaScript code should be executed in “strict mode” by the interpreter, whichi makes it easier to write “secure” JavaScript by changing previously accepted “bad syntax” into real errors.
'use strict';
...
The “use strict” directive is only recognized at the beginning of a script or a function.
In other words, it has to be first line in your code.
Things Not Allowed in Strict Mode
- Using a variable (or object) without declaring it with
var
(e.g. num = 10). - Deleting a variable, an object, or a function.
- Deleting an undeletable property.
- Duplicating a parameter name.
- Octal numeric literals (e.g. 020)
- Octal escape characters (e.g. “\010”)
- The word
eval
andarguments
cannot be used as variables. - The
with
statement (e.g. with (Math){x = cos(2)}) - For security reasons, eval() is not allowed to create variables in the scope from which it was called.