Strict mode of limit cirpt

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.