What is JS strict mode?

Source: Internet
Author: User

"03"

Strict mode

ECMAScript 5introduced a strict mode (Strict Mode) concept. The strict mode is forJavaScripta different parsing and execution model is defined. In strict mode,ECMAScript 3Some of the uncertainties in the behavior will be handled, and some unsafe operations will throw an error. To enable strict mode throughout the script, you can add the following code at the top:

    1. "use strict";

This line of code looks like a string, and it's not assigned to any variable, but it's actually a compilation instruction ( pragma ), to tell the supported JavaScript the engine switches to strict mode. This is a specially selected syntax for not destroying the ECMAScript 3 syntax.

Include this compilation instruction above the function, or you can specify that the function is executed in strict mode:

 

    1. < Code class= "Language-c" >function dosomething () {
    2. "use strict" ;
    3. //function body
    4. }

under strict mode,JavaScriptthe results of the implementation will vary greatly. Browsers that support strict mode includeie10+,Firefox 4+,Safari 5.1+,Opera 12+and theChrome.





What is JS strict mode?

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.