JavaScript and ANGULARJS syntax support strict mode: "Use strict"

Source: Internet
Author: User






If you label JavaScript and ANGULARJS code as "strict mode," all of the code running in it must be in strict mode.
One: If a syntax problem is found during syntax detection, the entire block of code is invalidated and a syntax exception is caused.
Second: If code that violates strict mode occurs during run time, an execution exception is thrown.



Note: Strict mode is not supported for tested ie6,7,8,9.



How to use the "strict mode" JavaScript code:
Strict mode requires the use of string sequences:



"Use Strict"


You can open the strict mode in the corresponding code block by adding the following:
1. You must join at the beginning of the global code.
2. Add at the beginning of the eval code.
3. Add at the beginning of the function declaration code.
4. The body parameter block passed in the new Function () begins to join.



Example 1:



var num =012;alert (num);



In non-strict mode, you can declare 8 binary with the prefix 0 (0). Display 10.



However, in strict mode, errors are generated.




"Use strict";

var num = 012;

alert (num);




Test results:
ie6,7,8,9 are shown in 10.
FF Error: Octal literals and octal escape sequences are deprecated
Chrome Error: uncaught syntaxerror:octal literals is not allowed in strict mode.
Opera error: Syntax error at line 3 while loading:invalid character var num = 012;



If you use strict mode, in addition to the 0 (0) prefix 8 binary, there are:
1. You cannot use some extended reserved words in your code:
Implements,interface,let,package,private,public,static,yield
2.with statements are also not available.
3. Eval and arguments two identifiers cannot be declared or overridden.
4. You cannot remove an explicitly declared identifier, name, or named function with delete.



JavaScript and ANGULARJS syntax support strict mode: "Use strict"


Related Article

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.