The best JavaScript Operators Tutorial In 2024, In this tutorial you can learn Examples,JavaScript Arithmetic Operators,JavaScript Assignment Operators,+ Operator for string,Examples,Examples,Examples,Strings and numbers adder,Examples,
= Operator for assignment.
+ Operator for VAT.
= Operator is used to JavaScript variable.
Arithmetic operator + is used to add value.
Specify the value of the variable, and the values are added:
After the above statement is executed, the value of x is:
y = 5, the following table explains these arithmetic operators:
运算符 | 描述 | 例子 | x 运算结果 | y 运算结果 | 在线实例 |
---|---|---|---|---|---|
+ | 加法 | x=y+2 | 7 | 5 | 实例 » |
- | 减法 | x=y-2 | 3 | 5 | 实例 » |
* | 乘法 | x=y*2 | 10 | 5 | 实例 » |
/ | 除法 | x=y/2 | 2.5 | 5 | 实例 » |
% | 取模(余数) | x=y%2 | 1 | 5 | 实例 » |
++ | 自增 | x=++y | 6 | 6 | 实例 » |
x=y++ | 5 | 6 | 实例 » | ||
-- | 自减 | x=--y | 4 | 4 | 实例 » |
x=y-- | 5 | 4 | 实例 » |
JavaScript assignment operator is used to assign values to variables.
Given x = 10 and y = 5, the table below explains the assignment operator:
运算符 | 例子 | 等同于 | 运算结果 | 在线实例 |
---|---|---|---|---|
= | x=y | x=5 | 实例 » | |
+= | x+=y | x=x+y | x=15 | 实例 » |
-= | x-=y | x=x-y | x=5 | 实例 » |
*= | x*=y | x=x*y | x=50 | 实例 » |
/= | x/=y | x=x/y | x=2 | 实例 » |
%= | x%=y | x=x%y | x=0 | 实例 » |
+ Operator is used to add text or string variable (linked).
For the connection of two or more string variables together, use the + operator.
For the connection of two or more string variables together, use the + operator:
txt3 operation results are as follows:
To increase the space between two strings, we need to insert spaces into a string:
After the above statement is executed, the value of the variable txt3 included are:
Or the space into the expression ::
After the above statement is executed, the value of the variable txt3 included are:
Two numbers together and returns the sum of the numbers and, if the numbers are added and the string and returns a string following examples:
x, y, and z output is:
Rule: If the sum of the numeric string, the result will be a string!