A Grammatical composition:
1, case-sensitive:
Everything in ECMAScript, including variables, function names, and operators are case-sensitive. For example, text and text represent two different variables.
2. identifiers:
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 ($), and the number cannot begin.
2. Other characters can be letters, underscores, dollar signs, or numbers.
3. You cannot use keywords, reserved words, true, false, and NULL as identifiers.
3. Comments:
ECMAScript uses C-style annotations, including single-line comments and multiline comments. (note can be used for code description, and mode)
1, single-line comment://
2, multiline Comment:/*axxxxxxx*/(can nest single-line comments, but not nested multiple lines of comments)
4. Direct Volume (literal literal (constant)):
All direct quantities (literals) are the data values directly displayed in the program that cannot be changed.
/ / digital literal ' Li Tinghui ' // string literal false// boolean literal /js/ GI // Regular expression literal null// object literal
In ECMAScript version 3rd, expressions like array literals and object literals are also supported, as follows:
// object literal expression [// array literal expression
Two. Keywords and reserved words:
1. Key words:
A set of keywords that have a specific purpose, typically used to control the start or end of a statement, or to perform a specific operation.
The keyword cannot be used as an identifier.
2. Reserved words:
A 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:
1. Variable Overview:
JavaScript variables are loosely typed , and so-called loose types are used to hold any type of data without declaring the data type that the variable holds.
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. (but this is difficult for later maintenance, and performance is not high, resulting in high costs!) )
var box = "java"= +; alert (box);
2. Considerations for Defining variables:
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 this is a very bad programming habit, remember not).
var box= ' Li Tinghui 'var age=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 are aligned.
var box= ' Li Tinghui '=, height;
JavaScript syntax, key reserved words and variables