Comparison Operators

Comparison Operators

  • Compares operands (the things on either side of the operator) and returns true or false (boolean) based one the comparison
Operator Description Example (all return true)
Equal (==) Returns true if the operands are equal 3 == “3” (uhmm yes this is actually true)
Not equal (!=) Returns true if the operands are not equal. (4 + 1) != 10
Strict equal (===) Returns true if the operands are equal and of the same type (8 * 1) === 8
Strict not equal (!==) Returns true if the operands are of the same type but not equal, or are of different type 3 !== “3”
Greater than (>) Returns true if the left operand is greater than the right operand 10 > (3 * 3)
Greater than or equal (>=) Returns true if the left operand is greater than or equal to the right operand 10 >= (3 * 3) + 1
Less than (<) Returns true if the left operand is less than the right operand 7 < (3 * 3)
Less than or equal (<=) Returns true if the left operand is less than or equal to the right operand 18 <= 6 * 3

Examples

JS Bin on jsbin.com