Javascript Basic Tutorial Operators
Operator
First we need to know what an expression is
For example i++; a+b These are all expressions
Unary operator: can only operate one value operator, called the unary operator
increment ++ and decrement- -
Look at the following code:
运算符
The front is incremented, output 101 The rear is incremented and output 101
The front is decremented, the output is 99 The rear decrement is output 99
Note: The difference between preposition and postposition
var box=100;
//age = ++box; //First add the box to 101, and then assign it to age
//= box ++; //First assign box to age, age=100, and then accumulate
//age = --box //First reduce box to 99, Then assign the value to age
//= box -- //First assign the box value to age age=100, and then subtract
+ -Operator
var box=100;
+box; //Positive number
-box //Negative number
The plus sign (+) has an automatic transformation function
As shown in the following code
一元运算符
Arithmetic operator
Add(+)
算术运算符
Minus(-)
算术运算符
Multiply(*)
算术运算符
Division(/)
算术运算符
remainder (%)
算术运算符
Assignment operator
Assignment operator Nested use of operators: the following case
赋值运算符
Comparison operator
Ternary operator
Syntax: Expression 1 ? Expression 2: Expression 3
Example:
三元运算符
Note: If expression 1 is true, the output result is expression 2, otherwise it is expression 3; For example, in the above case x=5;, judge whether expression 1 is true. If true, output the value of
##
&&(The conditions must be met at the same time to be true)
x=2;y=6;
x&&y>6 ;
At this time, x and y only have One item satisfies greater than 6, so the result is false;
||(As long as one of the conditions is met, it is true)
x=2;y=6;
x||y>6 ;
At this time, one of x and y satisfies the condition, so the result is true;
!(take The logic is worth the opposite, if it is true, take false, if false, take true)
x=5;y=8;
!(x>y);
First, judge whether x is greater than y. If it is not greater, it is false. If it is not false, it is true, so the result is true
##String linker +
字符串连接符