WHAT A LAMP Rotating Header Image

Operators of JavaScript

Every computer language has operators.

has following items:

There are two categories of operators. Binary: Two items (or operands) must be sandwiched on either side of the operator. Unary: onely one operand is required.

Arithmetic Operators

OperatorDescriptionExampleResult
+Additionx=2
y=2
x+y
4
-Subtractionx=5
y=2
x-y
3
*Multiplicationx=5
y=4
x*y
20
/Division15/5
5/2
3
2.5
%Modulus (division remainder)5%2
10%8
10%2
1
2
0
++Incrementx=5
x++
x=6
Decrementx=5
x–
x=4


Assignment Operators

OperatorExampleIs The Same As
=x=yx=y
+=x+=yx=x+y
-=x-=yx=x-y
*=x*=yx=x*y
/=x/=yx=x/y
%=x%=yx=x%y



Comparison Operators

OperatorDescriptionExample
==is equal to5==8 returns false
===is equal to (checks for both value and type)x=5
y="5"

x==y returns true
x===y returns false

!=is not equal5!=8 returns true
>is greater than5>8 returns false
<is less than5<8 returns true
>=is greater than or equal to5>=8 returns false
<=is less than or equal to5<=8 returns true



Logical Operators

OperatorDescriptionExample
&&and x=6
y=3

(x < 10 && y > 1) returns true

||or x=6
y=3

(x==5 || y==5) returns false

!not x=6
y=3

!(x==y) returns true



Operator Precedence

From lowest to highest

OperatorSyntax
semicolon;
comma,
assingment=, +=, -=, *=, /=, %=
conditional?:
logical "or"||
logical "and"&&
equality==, !=
relational<, <=, >, >=
mathematical+, -, *, /, %
unary!, -, ++, —
call()

Related posts

Comments are closed.