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:mynickname,book123 , etc.
Comments
ECMAScript uses C -style annotations, including single-line comments and block-level annotations.
single-line comment
/*
* This is a multi-line
* Notes
*/
Direct Volume ( literal literal)
All Direct Quantities ( literal ) is the data value that is displayed directly in the program.
+// digital literal
' eon ' // string literal
False// Boolean literal
/JS/GI// Regular expression literals
Null// object literal
in the ECMAScript version 3 , 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 All keywords
Break |
Else |
New |
Var |
Case |
Finally |
Return |
void |
Catch |
For |
Switch |
While |
Continue |
function |
This |
With |
Default |
If |
Throw |
|
Delete |
Inch |
Try |
|
Do |
instanceof |
typeof |
|
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.
ECMAScript-262 all reserved words defined in version 3
Abstract |
Enum |
Int |
Short |
Boolean |
Export |
Interface |
Static |
Byte |
Extends |
Long |
Super |
Char |
Final |
Native |
Synchronized |
Class |
Float |
Package |
Throws |
Const |
Goto |
Private |
Transient |
Debugger |
Implements |
Protected |
Volatile |
Double |
Import |
Public |
|
Three Variable
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= ' Zhang San ';
alert (box);
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! )
var boxstring = ' Zhang San ';
boxstring = 100;
alert (boxstring);
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= ' Zhang San ';
var box= ' John Doe ';
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, we will discuss in detail in the scope that section.
Box= ' Zhang San ';
When you want to declare multiple variables, you can do it in one or more rows.
var box= ' Zhang San '; var age=;
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= ' Zhang San '
var age= 100
Alert (Box)
You can use one statement to define multiple variables, as long as each variable ( can be initialized or not initialized ) separated by commas, for readability, each variable, preferably another row, and the second variable and the first variable are aligned (PS: These are not required ) .
var box= ' Zhang San ',
Age = 28,
Height
JavaScript (Next day)