JS Elevation 3. Basic Concepts (1)

Source: Internet
Author: User

1. syntax

(1) everything in ECMAScript (variables, function names, and Operators) is Case-sensitive.

(2) identifiers

The first character of an identifier must be a letter, underscore, or dollar SIGN.

Other characters can be letters, underscores, dollar signs, and Numbers.

    The ECMAScript identifier is in Camel-case format.

(3) Strict model (strict Mode)

Strict mode is for JavaScript to define a different parsing and execution model. In strict mode, some of the indeterminate behavior in ECMASCRIPT3 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:

    "use strict";

It is a compilation instruction (pragma) that tells the supported JavaScript engine to switch to strict mode.

2. Keywords and reserved words ( elevation P21)

3. variables

ECMAScript variables are loosely typed and can hold any type of Data.

Define variables using the var Operator.

Attention:

 A variable defined with the var operator becomes a local variable in the scope that defines the Variable. That is, if a variable is defined in the function, it is destroyed when the function Exits.

eg

1 <Scripttype= "text/javascript">2         functionTest () {3             varmessage="Hi";4         }5 Test ();6 Alert (message);7     </Script>

The result is an error:

Here the message is defined using VAR in the Function. When the function is called, the variable is created and assigned a value, and the variable is immediately destroyed, so an error is caused when the alert () function is Used.

When you omit the Var operator, you can define a global variable so that whenever you call the test () function, the variable is defined and accessible anywhere outside of the Function.

1 <Scripttype= "text/javascript">2         functionTest () {3 message="Hi";4         }5 Test ();6 Alert (message);7     </Script>

Attention:

Although omitting the var operator can define global variables, it is not recommended because it is difficult to maintain a global variable in a local scope, and if the Var operator is deliberately ignored, it can cause unnecessary confusion because the variable is not immediately defined.

  Assigning a value to an undeclared variable causes a Referenceerror error to be thrown in strict mode.

In strict mode, a variable named eval or arguments cannot be defined, or a syntax error occurs.

The eval () function, the arguments object, is in Javascript.

JS Elevation 3. Basic Concepts (1)

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.