JavaScript Operators
= Operator for assignment.
+ Operator for VAT.
= Operator is used to JavaScript variable.
Arithmetic operator + is used to add value.
Examples
Specify the value of the variable, and the values are added:
z=2;
x=y+z;
After the above statement is executed, the value of x is:
try it"
JavaScript Arithmetic Operators
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 Operators
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 for string
+ Operator is used to add text or string variable (linked).
For the connection of two or more string variables together, use the + operator.
Examples
For the connection of two or more string variables together, use the + operator:
txt2="nice day";
txt3=txt1+txt2;
txt3 operation results are as follows:
try it"
To increase the space between two strings, we need to insert spaces into a string:
Examples
txt2="nice day";
txt3=txt1+txt2;
After the above statement is executed, the value of the variable txt3 included are:
try it"
Or the space into the expression ::
Examples
txt2="nice day";
txt3=txt1+" "+txt2;
After the above statement is executed, the value of the variable txt3 included are:
try it"
Strings and numbers adder
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:
Rule: If the sum of the numeric string, the result will be a string!