Categories
JavaScript Answers

How to check if a number is between two values in JavaScript?

Spread the love

Sometimes, we want to check if a number is between two values in JavaScript.

In this article, we’ll look at how to check if a number is between two values in JavaScript.

How to check if a number is between two values in JavaScript?

To check if a number is between two values in JavaScript, we can use comparison operators.

For instance, we write

if (windowSize > 100 && windowSize < 200) {
  // ...
}

to check if windowSize is between 100 and 200 exclusive with

windowSize > 100 && windowSize < 200

It returns true if windowSize is between 100 and 200 excluding the end numbers.

Conclusion

To check if a number is between two values in JavaScript, we can use comparison operators.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *