Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To check if a number is between two values, Apply greater then and less than both conditions with and ( && ) operator. if get true means a number in a range.

Note: Here we are using && operator to reduce the number of codes, there have a lot of ways to do that

Today, I’m going to show How do I check if a number is between two values in javascript, here I will write some conditions and an if... else statement to check if a number is between a range or not.

Let’s start the today’s tutorial How do you check if the number is between two values in javascript?

In the following example

  1. I will set low and high numbers
  2. I will sample the input number example
  3. Write greater than and less than conditions to check number is between range or not
const inputNum = 70;

const lowest = 30;
const highest = 150;

if (inputNum > lowest && inputNum < highest) {
  console.log('âś… inputNum is between values');
} else {
  console.log('⛔️ inputNum is NOT between values');
}

In the above program, we have the highest and lowest values of desired range and use our condition to check the input number in two values or not.

let’s check the output.

javascript, check if a number is between two values example
javascript, check if a number is between two values or not example

I hope it’s help you, All the best 👍.