The "Use strict" state indicates that the browser uses strict mode, which is a relatively small and secure set of features in JavaScript.
Feature List (not fully enumerated)
- Defining global variables is not allowed. (Captures spelling errors for variables and variable names that are not declared with Var)
- A declaration that causes a silent failure in strict mode throws an exception (declares NaN = 5)
- Attempting to delete a property that cannot be deleted throws an exception (delete object. Prototype
- All property names in an object are unique (var x = {x1: "1", X1: "2"})
- The parameter name of the function must be unique (function sum (x, x) {...} )
- Disables the use of octal numeric syntax (var x = 023; Some developers mistakenly think that the previous 0 does not change the numbers)
- Prohibit use with keyword
- Eval does not introduce new variables in strict mode
- Prohibit Delete declaration variable (delete x)
- binding or assigning eval and arguments in any form is prohibited
- Strict mode does not synchronize the values of the arguments object to the parameter. (for example, in the function sum (A, b) {return arguments[0] + b}, this is written because Arguments[0] is bound to a, and so on. in normal mode, for a function where the first parameter is ARG, the value of ARG is assigned to Arguments[0] and vice versa (unless there are no arguments, or arguments[0] is deleted). In strict mode, the arguments object of the function saves the original arguments when the function is called. The value of arguments[i] does not change with the value of the corresponding parameter, and the value of the parameter with the same name will not change with the value of the corresponding arguments[i].
- Arguments.callee is no longer supported.
Translated from: http://stackoverflow.com/questions/1335851/ What-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it & Answerd by Gprasant
A more detailed description of the Mdn:https://developer.mozilla.org/zh-cn/docs/web/javascript/reference/strict_mode
RELATED links: https://tc39.github.io/ecma262/#sec-strict-mode-of-ecmascript
http://yanhaijing.com/es5/#about
Strict mode in JavaScript (translated)