Basic JavaScript tutorial Arithmetic Operators
Operator |
Operator description |
Example |
Example |
+ |
Addition |
X + Y |
If X is an integer of 2, Y is an integer of 5, X + Y is equal to 7 If X is the string "text1" and Y is the string "fun ", X + Y equals to "text1fun" |
- |
Subtraction |
X-y |
|
* |
Multiplication |
X * y |
|
/ |
Division |
X/y |
|
% |
Division of the two |
X % Y |
If X is equal to 10, Y is equal to 3, and X % Y is equal to 1 |
++ |
Increment |
X ++ |
If X equals 10, X ++ equals 11 |
-- |
Decrease |
Y -- |
If y equals 10, y -- equals 9 |
Basic JavaScript tutorial logical operators
Operator |
Operator description |
Example |
Example |
= |
Equal |
X = y |
If X equals 2 and Y equals 2, x = y |
=== |
All equals (values are equal, and data types are equal) |
X = y |
If X is equal to integer 2 and Y is the string "2 ", Then X = y is not true. |
> |
Greater |
X> Y |
|
> = |
Greater than or equal |
X> = y |
|
< |
Less |
X <Y |
|
<= |
Less than or equal |
X <= y |
|
! = |
Not equal |
X! = Y |
|
! = |
Not equal |
X! = Y |
|
&& |
And) |
X <10 & Y> 1 |
|
! |
Not) |
! (X = y) |
|
| |
Or (OR) |
X = 8 | Y = 8 |
|
Basic JavaScript tutorial assignment operator
Operator |
Operator description |
Example |
Example |
= |
Assignment |
X = 5 |
Assign the value of integer 5 to variable X |
Note:: Pay attention to the difference between value assignment (=) and equal to (=.