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,

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:

y=5;
z=2;
x=y+z;

After the above statement is executed, the value of x is:

7



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:

txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;

txt3 operation results are as follows:

What a verynice day

To increase the space between two strings, we need to insert spaces into a string:

Examples

txt1="What a very ";
txt2="nice day";
txt3=txt1+txt2;

After the above statement is executed, the value of the variable txt3 included are:

What a very nice day

Or the space into the expression ::

Examples

txt1="What a very";
txt2="nice day";
txt3=txt1+" "+txt2;

After the above statement is executed, the value of the variable txt3 included are:

What a very nice day



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:

Examples

x=5+5;
y="5"+5;
z="Hello"+5;

x, y, and z output is:

10
55
Hello5

Rule: If the sum of the numeric string, the result will be a string!

JavaScript Operators
10/30