Home >Web Front-end >Front-end Q&A >How to express less than or equal to in javascript

How to express less than or equal to in javascript

青灯夜游
青灯夜游Original
2022-11-15 19:18:104568browse

In JavaScript, less than or equal to can be represented by the "

How to express less than or equal to in javascript

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(&#39;aa&#39; <= &#39;ab&#39;);
// expected output: true

How to express less than or equal to in javascript

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 (

String and string comparison

console.log("a" <= "b");     // true
console.log("a" <= "a");     // true
console.log("a" <= "3");     // false

How to express less than or equal to in javascript

String and numerical comparison

console.log("5" <= 3);       // false
console.log("3" <= 3);       // true
console.log("3" <= 5);       // true

How to express less than or equal to in javascript

console.log("hello" <= 5);   // false
console.log(5 <= "hello");   // false

How to express less than or equal to in javascript

Comparison of numerical values ​​and numerical values

console.log(5 <= 3);         // false
console.log(3 <= 3);         // true
console.log(3 <= 5);         // true

How to express less than or equal to in javascript

##Comparison of numerical values ​​and large integers

console.log(5n <= 3);        // false
console.log(3 <= 3n);        // true
console.log(3 <= 5n);        // true

How to express less than or equal to in javascript

Compare Boolean, null, undefined and NaN

console.log(true <= false);  // false
console.log(true <= true);   // true
console.log(false <= true);  // true

How to express less than or equal to in javascript

console.log(true <= 0);      // false
console.log(true <= 1);      // true

How to express less than or equal to in javascript

console.log(null <= 0);      // true
console.log(1 <= null);      // false

How to express less than or equal to in javascript

console.log(undefined <= 3); // false
console.log(3 <= undefined); // false

How to express less than or equal to in javascript

console.log(3 <= NaN);       // false
console.log(NaN <= 3);       // false

1How to express less than or equal to in javascript

[Recommended learning:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn