JS Strict mode

Source: Internet
Author: User

Use Strict is a feature of ECMASCRIPT5 and is not recommended to be used globally, because when you compress different files, a file uses the use strict, a file that is not used, and does not use strict will be error-free.

1. Role

Eliminate the problem that JS syntax is unreasonable, not rigorous, unsafe, improve compiler efficiency, increase running speed

2. Supported Browsers

Ie10+,firefox4+,safari12+,opera12+,chrome

3. Rules

Variable:

Create global variable eg:name = "Bella" is not allowed;

You cannot delete a variable eg:var name = "Bella"; Delete name;

Object:

Cannot assign a value to a read-only property:

ECMAscript5 appeared the Object.definepropotype method changed the JavaScript language in which all object is public;

Object.definepropotype (obj,prop,descriptor): objects that need to be added or modified, property names, property descriptions;

var person = {name: ' Bella ', Sex: ' Female '};object.definepropotype (person, ' name ', {value: ' Alias ', Writable:false})

You cannot use the delete operation for a non-configurable property

Not configurable is also set by Object.definepropotype.

var person = {name: ' Bella ', Sex: ' Female '};object.definepropotype (person, ' name ', {configurable:false})

Function:

Parameter must be unique Eg:function (a,a) {}

Modifying a parameter does not affect arguments eg:funtion (arg1) {arg1 = "Bella";} Arguments[0]:bella,arguments was modified in non-strict mode

Use of Arguments.callee and Arguments.caller is not allowed

Eval () is not allowed to create a variable or function in the containing context

Eval is rarely used, because Eval executes the string as a JS code, changing the context Eg:eval ("var x = 10"); Alert (x) This is not allowed

This is not allowed to be null or undefined

Using with statements is not allowed

Octal literals are not allowed

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.