Operators are the symbols used to perform an operation.
1. Arithmetic operators:
It is a binary operator. It is used to perform addition(+), subtraction(-), division (/), multiplication(*), modulus(%-gives the remainder), increment(++) and decrement(—) operations.
Eg. If x=10 and y=3 then
x+y |
x-y |
x*y |
x/y |
x%y |
13 |
7 |
30 |
3.333 |
1 |
lf x=10 then
document.write(++x); → It prints 10+1=11
If x=10 then
document.write(x++); → It prints 10 itself.
If x=10 then
document.write(—x); It prints 10-1=9
lf x=10 then
document.write(x—); → It prints 10 itself.
2. Assignment operators:
If a=10 and b=3 then a=b. This statement sets the value of a and b are same, i.e. it sets a to 3.
It is also called short hands If X=10 and Y= 3 then
3. Relational(Comparison) operators:
It is used to perform comparison or relational operation between two values and returns either true or false.
Eg: If X=10 and Y=3 then
X<y |
X<=Y |
X>Y |
X>=Y |
X==Y |
X!=Y |
false |
false |
true |
true |
false |
true |
4. Logical operators:
Here AND(&&), OR(||) are binary operators and NOT(!) is a unary operator. It is used to combine relational operations and it gives either true or false
If X=true and Y=false then
X && X |
X && Y |
Y && X |
Y && Y |
true |
true |
true |
false |
Both operands must be true to get a true value in the case of AND(&&) operation
If X=true and Y=false then
X||X |
X||Y |
Y||X |
Y||Y |
true |
true |
true |
false |
Either one of the operands must be true to get a true value in the case of OR(||) operation
If X= true and Y=false then
5. String addition operator(+):
This is also called concatenation operator. lt joins(concatenates)two strings and forms a string.
Eg: var x, y, z;
x= “BVM HSS;
y= “Kalparamba”;
z=x+y;
Here the variable z becomes “BVM HSS Kalparamba”.
Note: If both the operands are numbers then addition operator(+) produces number as a result otherwise it produces string as a result.
Consider the following