JS: Number Comparison Operators

By Xah Lee. Date: . Last updated: .

Greater Than, Less Than

greater than:

4 > 3
// does automatic type conversion
console.log(4 > "3");

less than:

3 < 4
// does automatic type conversion
console.log(3 < "4");

greater or equal:

3 >= 3
// does automatic type conversion
console.log(3 >= "3");

less or equal:

3 <= 4
// does automatic type conversion
console.log(3 <= "4");

test equality:

console.log(3 == "3");
// note: double-equal does automatic type conversion

console.log((3 === "3") === false);
// triple-equal does not do type conversion

test inequality:

console.log(3 != 4);
// The 「!=」 is the negation of double-equal

console.log(3 !== 4);
// The 「!==」 is the negation of triple-equal

JavaScript, Operators

BUY ΣJS JavaScript in Depth

JavaScript, Number