1. Variables
Literally, a variable is a variable amount; From a programmatic standpoint, a variable is a memory used to store a certain number of values. We can think of variables as a box, boxes for storing items, items that can be clothes, toys, fruits ... such as
1.1 Variable naming rules
1.1.1. You must start with a letter, underscore, or dollar sign, followed by letters, underscores, dollar signs, and numbers.
1.1.2. Variable names are case-sensitive, such as: A and A are two different variables.
1.1.3. Do not allow variable names using JavaScript keywords and reserved words.
1.2 Variable Declaration
Declaring variable syntax: var variable name, such as Var mynum; Declare multiple variables var num1,mun2
2. Operators
2.1 + number operator
An operator is a symbol used to specify a certain action in JavaScript.
(1) operator
Look at the JavaScript code below.
sum = numa + numb;
"="and all of them "+" are operators.
There are many such operators in JavaScript, such as arithmetic operators (+ 、-、 *,/etc.), comparison operators (<, >, >=, <=, etc.), logical operators (&&, | |,!). )。
Note: the "=" operator is an assignment, not equal to.
(2) "+" operator
Arithmetic operators are primarily used to perform work similar to subtraction, where "+" does not just represent addition, but can also connect two strings, for example:
mystring = "Java" + "Script"; MyString the value "JavaScript" this string
2.2 Self-added one, self minus one (+ + and-)
In addition to the arithmetic operators (+ 、-、 *,/), there are two very common operators, self-added one “++” ; “--” Let's start with an example:
Mynum = 10;mynum++; The value of Mynum becomes 11mynum--; Mynum's value goes back to 10.
In the above example, mynum++ the Mynum value on the original basis to increase the 1,mynum--so that mynum on the original basis minus 1, in fact, can also be written as:
Mynum = Mynum + 1;//equals to mynum++
Mynum = mynum-1;//equivalent to mynum--
2.3 comparison operator <,>,<=,>=,==,!=, two operands are compared by comparison operators to get the value true (True) and False (false)
2.4 Logic and operators &&
Mathematics inside the "A>b", in JavaScript also expressed as a>b; mathematics "B is greater than a A, a small less than C" is "a<b<c", then in JavaScript can be used in &&, as follows:
B>a && b<c //"&&" is and means, reading "B is greater than a" and "B is less than C"
Logical OR operator
"||"Logical OR operator, equivalent to "or" in life, when any one of the two conditions satisfies, the result of "logical OR" is "true"
Logical non-operator
"!"is the logical non-operator, that is, the meaning of "no", not true or false, not false is true.
Operator Precedence
The precedence of the operators of division and multiplication is higher than that of addition and subtraction, to change the order of operations, the method of adding parentheses is required to change the precedence:
Precedence between operators (high-to-low):
Arithmetic operator → comparison operator → logical operator → "=" assignment symbol
If the operation of the sibling is done in the left-to-right order, the multi-level brackets are outward.
JavaScript basic syntax