Javascript Comparisons

Comparison Operators

Comparison operators are used in logical statements to determine equality or difference between variables or values, and test for true or false.

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, 0 and undefined 

EquationReturns
 == 
 if (x ==1)true if x = 1;
 if (x ==1)true if x = "1";
 if (x ==0)true if x = 0;
  if (x ==0)true if x = null;
  if (x ==0)true if x = undefined;
 === 
 if (x ===1) true if x = 1;
 if (x ===1) false if x = "'1";
 if (x ===0) true if x = 0;
 if (x ===0) false if x = null;
 if (x ===0) false if x = undefined;