In JavaScript, less than or equal to can be represented by the "
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, less than or equal to can be expressed using the "
"
The "
The "
Example:
console.log(5 <= 3); // expected output: false console.log(3 <= 3); // expected output: true // Compare bigint to number (note: bigint is not supported in all browsers) console.log(3n <= 5); // expected output: true console.log('aa' <= 'ab'); // expected output: true
Syntax:
x <= y
If the left operand is less than or equal to the right operand, return true, otherwise return false.
Usage of less than or equal to (<=) operator
String and string comparison
console.log("a" <= "b"); // true console.log("a" <= "a"); // true console.log("a" <= "3"); // false
String and numerical comparison
console.log("5" <= 3); // false console.log("3" <= 3); // true console.log("3" <= 5); // true
console.log("hello" <= 5); // false console.log(5 <= "hello"); // false
Comparison of numerical values and numerical values
console.log(5 <= 3); // false console.log(3 <= 3); // true console.log(3 <= 5); // true
##Comparison of numerical values and large integers
console.log(5n <= 3); // false console.log(3 <= 3n); // true console.log(3 <= 5n); // true
Compare Boolean, null, undefined and NaN
console.log(true <= false); // false console.log(true <= true); // true console.log(false <= true); // true
console.log(true <= 0); // false console.log(true <= 1); // true
console.log(null <= 0); // true console.log(1 <= null); // false
console.log(undefined <= 3); // false console.log(3 <= undefined); // false
console.log(3 <= NaN); // false console.log(NaN <= 3); // false
javascript advanced tutorial】
The above is the detailed content of How to express less than or equal to in javascript. For more information, please follow other related articles on the PHP Chinese website!