Javascript's loose and flexible syntax has been controversial for a long time. Therefore, the strict mode is introduced in the definition of ECMAScript 5.0, so that the Javascript interpreter can use the "strict" syntax to parse the code to help developers find errors. Strict mode is supported in IE 10.
It is easy to enable strict mode. Add it at the beginning of the Code.
[Javascript]
"Use strict ";
In this way, it is cleverly compatible with browsers that do not support strict mode and will not report errors.
Strict mode has the following benefits:
Prevent unexpected global variables
[Javascript]
"Use strict ";
X = 5; // if no statement is made, an error is returned.
Cancel automatic conversion of this value
[Javascript] view plaincopy
Window. hi = "Hi ";
Function sayHi (){
Alert (this. hi); // Error
}
Prevent repeated Definitions
[Javascript]
Var someObject = {
Prop: "test ",
Prop: "test2" // Error
};
In addition, strict mode removes the support for with statements, and variables declared in eval are not created in the inclusion domain.
Finally, we recommend that you use strict mode in JavaScript code to detect hidden errors earlier.
Author: WinGeek