The strict mode and normal mode of JavaScript

Source: Internet
Author: User

Adding "use strict" to the JS code is equivalent to entering strict mode, and strict mode changes the syntax and runtime behavior to turn hidden problems into errors.

The strict mode of JS has the following features:

First, variable declaration

Global variables must be declared before they can be used, and if not declared with Var, they will be used without error.

Second, function declaration

You cannot declare a function within a block of code that is not a function, such as an if statement, a loop statement.

Third, static binding

In the compilation phase, you determine which object the property and method belong to.

1. Prohibit use with statement

Because the WITH statement cannot be determined at compile time, the property exactly belongs to which object.

2. Eval scope

In normal mode, only the global and function scopes, in strict mode, will have the eval scope.

Four, this

When using a constructor, if you do not use New,this to point to the window, you will get an error.

Five, delete

Cannot delete a variable, only an object property with configurable set to True can be deleted.

Deleting a read-only property will cause an error.

Six, can not duplicate the name

Object properties cannot have duplicate names, and function parameters cannot have duplicate names.

The strict mode and normal mode of JavaScript

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.