Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For example, given that x = 5, the table below explains the comparison operators: 

OperatorDescriptionComparingReturns
==equal tox == 8false
x == 5true
x == "5"true
===equal value and equal typex === 5true
x === "5"false
!=not equalx != 8true
!==not equal value or not equal typex !== 5false
x !== "5"true
x !== 8true
>greater thanx > 8false
<less thanx < 8true
>=greater than or equal tox >= 8false
<=less than or equal tox <= 8true

 Oddities of Null

 

 

 

Operator
Equation
Description
Returns
Comparing
 ==
Returns
 
 if (x ==
equal to
1)true if x = 1;
 if (x ==
8false
1)true if x = '1';
 if (x ==
5
0)true if x = 0;
  if (x ==
"5"
0)true if x = null;
  if (x ==0)true if x =
equal value and equal typex === 5truex === "5"false
undefined;
 === 
 if (x ==1) 
 if (x ==1) 
 if (x ==0) 
 if (x ==0) 
 if (x ==0) 
  
  
 
 
false