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.