8-point rule in JavaScript strict mode

Source: Internet
Author: User

Role

[1] The elimination of some of the JS syntax unreasonable, not rigorous, unsafe problems, reduce weird behavior and ensure that the code is safe to run

[2] Improve compiler efficiency, increase operating speed

Use

[1] The entire script is enabled in strict mode, at the top of the execution: "Use strict";

[2] Execution of strict mode in the specified function, the first line of the function body: "Use strict"

[3] browsers that do not support strict mode execute "use strict" as a string statement, and browsers that support strict mode will turn on strict mode

[4] A browser that supports strict mode includes ie10+, firefox4+, safari12+, opera12+, Chrome

Rules
"1" "Variable"
[A] does not allow accidental creation of global variables

"Use strict"= ' Hello world! ';

[B] cannot call the delete operator on a variable

"Use strict"; var color = ' red '; delete color;

"2" "Object"
[A] cannot assign a value to a read-only property

"Use strict"; var person = {    name:' Cook '};object.defineproperty (person,' name ', {     false  = ' Nicholas ';

[B] Cannot use the delete operation for a non-configurable property

"Use strict"; var person = {    name:' Cook '};object.defineproperty (person,' name ', {     false }); Delete person.name;

"3" function
[A] parameter must be unique

"Use strict"; function Sun (num,num) {    //TODO}

[b] Modifying the parameter is not reflected in the arguments

function Showvalue (value) {    = "Foo";    Alert (arguments[0]);     // non-strict mode: "Foo"    // Strict mode: "Hi" }showvalue ("Hi");

[C] not allowed to use Arguments.callee and Arguments.caller

"Use strict"; function fn (num) {    return  arguments.callee (num);} FN (2);
"Use strict"; function outer () {    inner ();} function inner () {    alert (Inner.caller ());} Outer ();

' 4 ' does not allow Eval () to create a variable or function in the containing context

"Use strict"; function fn () {    eval ("var x=10");    alert (x);} fn ();
// allow the following actions var result = eval ("var x = ten, y = 11; X+y "); alert (result); //  +

"5" does not allow eval and arguments as identifiers, nor is it allowed to read and write their values

"Use strict"; var eval = ten; var arguments = 20;

' 6 ' does not allow this value to be null or undefined

"Use strict"; var color = "Red"; function fn () {    alert (this. color);} fn ();

' 7 ' does not allow the WITH statement

"Use strict";  with (location) {    alert (href);}

' 8 ' does not allow the use of octal literals

"Use strict"; var value = 010;

8-point rule in JavaScript strict mode

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.