ECMAScript's syntax draws heavily on the syntax of C and other C languages such as Java and Perl.
1. case-sensitive
2. identifiers
2.1 The first character must be a letter, an underscore (_), or a dollar sign ($);
2.2 Other characters can be letters, underscores, dollar signs, or numbers
By convention, The ECMAScript identifier is in Hump-case format, which is the first lowercase letter, and the first letter of the remaining words is Capitalized.
3. Notes
Same as C language
Single-line Comment
/* just a multi-line
* Notes
*/
4. Strict Mode "use strict"
5. The statement ends with a semicolon, and if the semicolon is omitted, the interpreter determines the end of the statement, although the semicolon at the end of the statement is not required, it is not recommended to omit it at any Time.
6. Keywords and reserved words
Break does instanceof typeof case Else new Var catch finally return void continue to switch while debugger* function this W ith default if throw delete in tryabstract enum int short Boolean export interface static byte extends long super char fin Al native Synchronized class float package throws const GOTO private Transient debugger implements protected volatile Doub Le import public
7. Variable Definition
var message= "hi";
var value=1.0;
8. Data Type
5 Basic Data Types: undefined,null,boolean,number,string, and a complex data type Object
ECMAScript does not support any mechanism for creating custom types, and all of the values will eventually be one of the 6 data types mentioned Above.
typeof operator
var message= "hello"; Console.log (typeof (message)); -->string
var value=100.9; Console.log (typeof (value)); -->number
Undefined type, The uninitialized value gets the undefined value by Default.
Null type, using the typeof operation to return an object
Boolean type
Number Type
number.max_value, numer.negative_infinity,number.positive_infinity
NaN (not a Numebr Non-numeric)
Number () function Conversion rule:
A. If it is a Boolean value, true and False are converted to 1 and 0, respectively.
B. If it is a numeric value, simply pass in and return
C. If it is a null value, returns 0
D. If it is undefined, return Nan
E. If it is a string, it will do a c-like conversion, the conversion is unsuccessful, return Nan
F. If it is an object, the valueof () method of the object is called, and the returned value is converted according to the preceding Rule. If the result of the conversion is nan, the tosring () method of the object is called, and then the returned string value is converted again according to the previous Rule.
Object type
var o=new Object ();
If you do not pass arguments to the constructor, you can omit the following pair of parentheses, such as Var o=new object;
Each instance of object has the following properties and METHODS.
constructor, hasownproperty (propertyname), isprototypeof (object), propertyisenumerable (propertyname), tolocalestring, Tostring,valueof.
operator + +,--, +,-, *,/,%, &, | , ~, <<, >>, >>>
Boolean operator
! , &&,| |
Relational operators
<,>,<=,>=, ==,!=,===,!==
Statement:
If (contition) statement1 else statement2
If (condition1) statement1
else F (condition2)
Statement2
else Statement3
Do{statement
} while (expression);
While (expression) statement;
For (initialization; expression; Post-loop-expression) statement;
For (property in Expression) statement;
It is recommended to detect that the value of the object is not null or undefined before using the for-in loop.
Label Statement: use the label statement to add tags to your code for future Use.
Break and continue with the C language, controlling code execution in the loop body.
With statement, The main purpose is to simplify the work of writing the same object multiple Times. (with statement not allowed in strict mode)
With (expression) statement
var qs=location.search.substring (1);
var hostname=location.hostname;
var url=location.href;
The above code contains the location object, and if you use the Swith statement, you can rewrite the above code as Follows:
With (location) {
var gs=search.substring (1);
var hostname=hostname;
var url=href;
}
Switch Statement: Same as the C language, but in js, any data type can be used in Switch.
Function
function functionname (arg0,arg1,..., argN) { statements;} E.g.function sayhi (name,message) {alert ("hello" + name + "," + message);}
You can pass any number of arguments to the JS function, and you can access them through the arguments Object.
The JS function cannot be overloaded because there is no characteristic of the function signature.
Basic concepts and syntax for JavaScript beginners