Skip to main content

What is the difference between == and === operator

Firstly

 "==" 

this equality check operator try to Coercion the two value

like

 3 == '3' 

in this case == operator try convert ‘3’ in number thats why

 3 == '3'  return true;

another example

 1 < 2 < 3 

what might you think the result will be ? result is true.
On the other hand

 3 < 2 < 1 

resutl also true. You may be confuse ……..
let see what is going here…

firstly example 1

 "1 < 2 < 3" 

this

 < 

comparison operator Associativity is left-to-right so this

'<'

comparison operator Associativity is left-to-right so

 1 < 2 

execute first and result true

then

 true < 3;

here true is going to convert number and converted result is 1

then

 1 < 3 

result is true.

But on the other hand

 '===' 

Strict Equality operator dont compare in this fashoine.

It just compare the value without convert or Coercion.

Like

 3 == '3' return true;

but

 3 === '3' return false;

So main difference between

 "==" 

and

 "==="

this

 "==" 

convert the value

and this

 "===" 

dont convert the value