Less than or equal (<=)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Theless than or equal (<=) operator returnstrue if the left operand is less than or equal to the right operand, andfalse otherwise.
In this article
Try it
console.log(5 <= 3);// Expected output: falseconsole.log(3 <= 3);// Expected output: true// Compare bigint to numberconsole.log(3n <= 5);// Expected output: trueconsole.log("aa" <= "ab");// Expected output: trueSyntax
x <= yDescription
The operands are compared using the same algorithm as theLess than operator, with the operands swapped and the result negated.x <= y is generally equivalent to!(y < x), except for two cases wherex <= y andx > y are bothfalse:
- If one of the operands gets converted to a BigInt, while the other gets converted to a string that cannot be converted to a BigInt value (it throws asyntax error when passed to
BigInt()). - If one of the operands gets converted to
NaN. (For example, strings that cannot be converted to numbers, orundefined.)
In addition,x <= y coercesx to a primitive beforey, whiley < x coercesy to a primitive beforex. Because coercion may have side effects, the order of the operands may matter.
x <= y is generally equivalent tox < y || x == y, except for a few cases:
- When one of
xoryisnull, and the other is something that's notnulland becomes 0 whencoerced to numeric (including0,0n,false,"","0",new Date(0), etc.):x <= yistrue, whilex < y || x == yisfalse. - When one of
xoryisundefined, and the other is one ofnullorundefined:x <= yisfalse, whilex == yistrue. - When
xandyare the same object that becomesNaNafter the first step ofLess than (such asnew Date(NaN)):x <= yisfalse, whilex == yistrue. - When
xandyare different objects that become the same value after the first step ofLess than:x <= yistrue, whilex < y || x == yisfalse.
Examples
>String to string comparison
"a" <= "b"; // true"a" <= "a"; // true"a" <= "3"; // falseString to number comparison
"5" <= 3; // false"3" <= 3; // true"3" <= 5; // true"hello" <= 5; // false5 <= "hello"; // falseNumber to Number comparison
5 <= 3; // false3 <= 3; // true3 <= 5; // trueNumber to BigInt comparison
5n <= 3; // false3 <= 3n; // true3 <= 5n; // trueComparing Boolean, null, undefined, NaN
true <= false; // falsetrue <= true; // truefalse <= true; // truetrue <= 0; // falsetrue <= 1; // truenull <= 0; // true1 <= null; // falseundefined <= 3; // false3 <= undefined; // false3 <= NaN; // falseNaN <= 3; // falseSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-relational-operators> |