Navigate back to the homepage

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

Infinitbility
JavaScript
June 4th, 2022 · 1 min read

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
1const inputNum = 70;
2
3const lowest = 30;
4const highest = 150;
5
6if (inputNum > lowest && inputNum < highest) {
7 console.log('✅ inputNum is between values');
8} else {
9 console.log('⛔️ inputNum is NOT between values');
10}

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 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

Guide to use onflow flow-js-testing framework

Example of use onflow flow-js-testing framework with step by step guide.

June 3rd, 2022 · 1 min read

How to create multiple nodes in the node-red single module?

Example of create multiple nodes in the node-red single module or package with step by step guide.

June 3rd, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]