ENOTES

Operators in JavaScript

access_time Mar 11, 2022 remove_red_eye 6674

Operators are the symbols or sign used to perform some specific operation.  Let us consider a simple expression c=a+b where, a, b and c are the operands. + = are the operators and addition is the operation.

Types of Operators in JS

1) Arithmetic Operator:

Arithmetic operator are symbol used for basic mathematical calculation such as addition, multiplication, division, subtraction, remainder etc.Operators are:

+Addition
-Subtraction
*Multiplication
/Division
%Remainder
++Increment
- -Decrement

Program example

<script>
var a=2,b=3,c=a+b;
document.write(c);
</script>

2. Comparison Operator:

Comparison operator are the symbol used to compare the values of two operands. Operators are:

==  Equals
!=Not equal to
<Less than
>Greater than
>=   Greater than equal
<=    Less than equal

Program example

<script>
var a=2,b=3,c=a+b;
if(a>b)
{
document.write(a);
}
else
{
document.write(b);
}
</script>

3. Logical operator:

Logical operator are used to make logical comparison i.e that logically connect two or more expression. Operator are:

&&Logical AND
||Logical OR
!Logical NOT

Program example

<script>
var a=2,b=9,c=7;
if(a>b && a>c)
{
document.write(a);
}
else if (b>a && b>c)
{
document.write(b);
}
else
{
document.write(c);
}
</script>

4: Assignment Operator:

This operator is used to assign value to a identifier(variable). Operator are:

=Simple equal to
+=Add and assign
-=Subtract and assign
*=Multiply and assign
/=Divide and assign
%Take remainder and assign

Program example

<script>
var a=2,b=3,c=a*b;
document.write(c);
</script>

5: String Operator 

This operator helps to add several  strings. The process of adding string is called string concatenation.

+ is the string operator used to add string.

Program example

<script>
var a=2,b=3,c=a+b;
document.write(“Sum is” + c);
</script>