Brief: Strict mode (strict modes) is a new encoding mode in JavaScript ES5, as long as a line of code can be opened, it is very simple, and it is what is the difference in our code?
First, the purpose of strict mode?
1, eliminate some of the JavaScript grammar unreasonable, not rigorous, reduce some strange behavior;
2, to eliminate some unsafe code operation, to ensure the security of code operation;
3, improve the efficiency of the compiler, increase the speed of operation;
4. Pave the new version of JavaScript for the future.
Second, how to use?
Just insert this line of code in the right place.
"Use strict";
1. For the script file
<script>
"Use strict"; Insert to this position, valid for all JS files
Console.log (Somecode);
</script>
2, for the Independent function
function A () {
"Use strict"; Inserted into this position, which is valid for this function
Console.log (Somecode)
}
Iii. What are the grammatical changes in strict mode?
1. Global variables must be explicitly declared
"Use strict";
A = 1; This error, because strict mode, can not be declared as a global variable, you must add Var and other declarations.
2, static binding, JavaScript dynamic binding received some restrictions, such as the With statement is no longer allowed (with statement is the runtime to bind the property, the method to which object)
3. Increase the eval () scope
Normal mode: 2, global scope, function scope; The scope of the eval at this time depends on whether it is under global scope or function scope;
Strict mode: 3 kinds, global scope, function scope, eval scope;
4. This no longer points to global objects
Means: When using the constructor, when the new keyword is not used, this will no longer default to the global window, and will error;
5. Prohibit traversal of the call stack inside a function
6. The variable cannot be deleted in strict mode. Only configurable object properties that are set to True can be deleted.
7, Normal mode, the read-only property of an object is assigned, will not error, will only silently fail . Strict mode, will be an error.
。。。 In subsequent updates
Read more : Please refer to Nanyi Teacher's blog http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html
JavaScript rigorous mode analysis