JavaScript syntax, key reserved words and variables

Source: Internet
Author: User

A Grammatical composition:

  Case Sensitive: Everything in ECMAScript, including variables, function names, and operators are case-sensitive. For example, text and text represent two different variables.

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

1. The first character must be a letter, an underscore (_), or a dollar sign ($).

2. Other characters can be letters, underscores, dollar signs, or numbers.
3. You cannot use keywords, reserved words, true, false, and NULL as identifiers.
For example: MyName, book123, etc.

  notes: ECMAScript uses C-style annotations, including single-line comments and block-level annotations. (note can be used for code description, and mode)

Single-line Comment

/*
* This is a multi-line comment
*/

  Direct Volume (literal literal (constant)): all direct quantities (literals) are the data values directly displayed in the program.

100//Digital literal

' Li Tinghui '//string literal
False//Boolean literal
/js/gi//Regular expression literals

Null//Object literal

In ECMAScript version 3rd, expressions like array literals and object literals are also supported, as follows:

{x:1, Y:2}//object literal expression

[1,2,3,4,5]//array literal expression

Two. Keywords and reserved words:

  ECMAScript-262 describes a set of keywords that are used for a specific purpose, typically to control the start or end of a statement, or to perform a specific operation. Keywords are also language-reserved and cannot be used as identifiers.

      

ECMASCRIPT-262 also describes another set of reserved words that cannot be used as identifiers. Although reserved words do not have a specific purpose in JavaScript, they are most likely to be used as keywords in the future.

      

three. 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). The so-called variable is the amount that can be changed again after initialization. ECMAScript is a weakly typed (loosely typed) language that can change the amount of different types at the same time. PS: Although different types of quantities can be changed, this is difficult for later maintenance, and the performance is not high, resulting in high cost! )

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;
alert (box);

Repeat using VAR to declare a variable, but it is an assignment operation, and does not give an error. But this kind of operation is the comparison of two, there is no need.

var box= ' Li Tinghui ';
var box= ' Lee ';

When you want to declare multiple variables, you can do it on one line (separated by semicolons) or multiple lines.

var box= ' Li Tinghui '; var age= 100;

You can omit semicolons when each statement is in a different row. (PS: This is ECMAScript support, but definitely a very bad programming habit, remember not).

var box= ' Li Tinghui '
var age= 100
Alert (Box)

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: These are not necessary).

var box= ' Li Tinghui ',
Age = 28,
Height

1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" />5 <title>JavaScript syntax, key reserved words and variables</title>6 <Scripttype= "Text/javascript">7     varbox;8 alert (box);9     varboxstring= 'Eon Restore';Ten boxstring=  -; One alert (boxstring); A alert (age);//there will be an error. - Alert ('javascript syntax, key reserved words and Variables'); - </Script> the </Head> -  - <Body> - Welcome to the world of JavaScript + </Body> - </HTML>



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.