JavaScript III (syntax, key reserved words and variables)

Source: Internet
Author: User

Basic concept One, case-sensitive

Everything in ECMAScript (variables, function names, operators) is case-sensitive.

The variable name test and test represent two different variables, respectively.

Second, identifiers

The so-called identifier refers to the name of a variable, function, property, or parameter of a function. One or more characters that are combined by identifiers according to the following formatting rules:

    • The first character must be a letter, an underscore (_), or a dollar sign ($);
    • Other characters can be letters, underscores, dollar signs, or numbers.
    • The ECMAScript identifier is in hump case format, that is, the first letter lowercase, and the first letter of each of the remaining words is capitalized, for example: Firstsecond,mycar,dosomethingimport
Third, comments

ECMAScript uses C-style annotations, including single-line comments and block-level annotations.

    • Single-line comment: Start with two slashes such as:
Single-line Comment
    • Block-level comments begin with a slash and an asterisk (/*), ending with an asterisk and a slash (*/) such as:
/** This is a multi-line * (Block-level) Comment */
Iv. statements

The statement in ECMAScript ends with a semicolon, and if you omit the semicolon, the parser determines the end of the statement, such as:

var sum = a + b   //Even if no semicolon is a valid statement-------does not recommend var diff =-A;  Recommended---------Valid statements

Although the ending semicolon is not required, it is recommended that you do not omit it at any time.

V. Keywords and reserved words

Keywords and reserved words: characters that have a specific purpose, which can be used to denote the start or end of a control statement, or to perform a specific operation.

Keywords and reserved words: cannot be an identifier or a property name.

ECMASCRIPT-262 also describes another set of reserved words that cannot be used as identifiers. Although reserved words in JavaScript
There are no specific uses, but they are most likely to be used as keywords in the future.

Vi. variables

The ECMAScript variable is loosely typed, and the so-called loose type is used to hold any type of data. Use the var operator when defining variables (Var is the key), followed by a variable name (the variable name is an identifier).

var box;alert (box);

This statement defines the box variable, but does not initialize it (that is, it does not assign a value to the variable). At this point, the system gives it a special value-undefined (which means undefined).

var box=100; alert (box);

This sentence defines the box variable and initializes it (that is, assigns a value to the variable). At this point, it pops up 100.

There is also a variable that does not require the preceding var keyword to create a variable. This variable and var variable have a certain difference and scope of action

abox= ' testing ';

You can use a statement to define multiple variables, as long as each variable (initialization or uninitialized can be) separated by commas, for readability, each variable, preferably another row, and the second variable and the first variable alignment (PS: this
are not necessary).

abox= ' Test ',
Age=18,
Height

JavaScript III (syntax, key reserved words and variables)

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.