How to Use the Less Than or Equal To Operator in JavaScript?

Estimated read time 1 min read

The less than or equal to operator in JavaScript is represented by <=. It is used to compare two values and determine whether the first value is less than or equal to the second value.

Here’s an example of how you could use the less than or equal to operator:

const number1 = 5;
const number2 = 10;

const result = number1 <= number2;
console.log(result); // true

In this example, we compare the values 5 and 10 using the less than or equal to operator. The expression number1 <= number2 returns true, indicating that 5 is less than or equal to 10.

You can also use the less than or equal to operator to compare strings:

const string1 = "apple";
const string2 = "banana";

const result = string1 <= string2;
console.log(result); // true

In this example, we compare the strings "apple" and "banana" using the less than or equal to operator. The expression string1 <= string2 returns true, indicating that "apple" is less than or equal to "banana".

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply