I. Declaration and use of variables
JavaScript is a weakly typed language with no explicit data type, and when declaring a variable, you do not need to specify the type of the variable, and the type of the variable is determined by the value assigned to the variable.
Syntax for variable declarations:
var variable name;
Example:
var num; // declare a variable directly, not assign a value var num = // declares a variable and assigns a value, and the type is determined by the value of the assignment.
Attention:
1, JavaScript is case-sensitive, especially the name of variables, statement keywords and so on.
2, the variable can be used without declaration, such as: num=20, but this method is easy to error, it is difficult to find the wrong, so it is not recommended.
Ii. Types of data
In JavaScript, a common basic data type is provided, as shown in the following table.
| Data type |
Meaning |
| Undefined |
Not defined |
| Null |
Null value |
| String |
String |
| Number |
Digital |
| Boolean |
Boolean type |
Attention:
1, although the meaning of undefined and null is different, but undefined is actually derived from null, ECMAScript defines them as equal.
2. The number type can be a 32-bit integer and can also represent a 64-bit floating-point number.
Third, operator
As in Java, JavaScript also contains operators, and the commonly used operators are shown in the following table.
1, arithmetic operators: + 、-、 *,/,%, + + 、--;
2, Comparison operators:>, <, >=, <=, = =,! =
3, logical operators:&&, | |,! ;
4, assignment operator: =;
Attention:
1, in JavaScript string equality is more practical "= =";
2. Determine which type a variable belongs to, using the typeof () operator.
Iv. Logical Control statements
JavaScript's logical control statements are also divided into two categories: conditional structure and looping structure, and syntax is similar to java.
1. Conditional structure:
If...else ...
Switch:
Note: Unlike switch in Java, a string type can be used in JavaScript after a case.
2. Cyclic structure:
For loop:
While loop:
Do...while Cycle:
For...in Cycle:
3. Flow Control statement:
Break: Exits the switch structure, or terminates the loop.
Continue: Terminates the current loop and enters the next loop.
V. Notes
JavaScript annotations are divided into two types, like Java:
1,//indicates a single line comment
2./**/for multiple lines of comment
Java Script Basics (ii) Basic syntax