Basic syntax of JS program
JS is case-sensitive. For example: Name and name are two variables
JS in each statement, usually the English semicolon (;) end. This semicolon is not required . In order to be compatible with PHP, it is best to add semicolons.
Operators and variables, and actions can be separated by spaces, such that the program is easier to read.
The type of the variable--that is, the data type
Data types of variables: numeric, character, boolean, undefined, NULL, array, object, function
The data types of variables are divided into two main categories:
Basic data types: numeric, character, Boolean, Undefined, empty. Notable feature: A variable name can only have one value.
Example: var a = 10;
Composite data types: arrays, objects, functions. Notable features: A variable name that may store multiple values.
Example: var arr = [10,20,30,40]
1 , numeric: Variables that can perform mathematical operations
Numeric types include: integer, float, NaN.
var a = 100;
var a = 0.9;
var a = 0;
There is also a very special value Nan in the numeric type. NaN (not a number) is not a digit.
When the other data type is converted to a numeric type, it cannot be passed, but the program cannot make an error, and a value of Nan will be returned.
2 , Character type: A string that is caused by single or double quotation marks.
var a = "I am a string";
var b = ' I am also a string ';
var c = "";
single and double quotation marks can be nested between each other
Only double quotation marks can be nested within single quotation marks;
Only single quotes can be nested within double quotation marks.
3 , type Boolean
Boolean type is also called logical type. There are only two values: true (True), False (false).
4 , non-defined
When a variable is defined but not assigned , the undefined type is returned, and the value of the undefined type has only one undefined.
An undefined type is also returned when the property of an object does not exist.
5 , empty type
When an object does not exist, a null type is returned, and the null value is only one null.
It can also be understood as: is a placeholder for an object.
If you want to clear the value of a variable, you can assign a null value.
var a = 100;
var a = null; Assigns a null to a variable that clears its value
Basic syntax of JS program