Check if a Number is Between Two Numbers in JavaScript-Code Examples

Radu TM

Check if a Number is Between Two Numbers in JavaScript

JavaScript by Radu TM June 21, 2022

if (num >= 10 && num <= 20) {
  console.log("🎉 Number is between 10 and 20!");
}

0

26.005

Check if a Number is Between Two Numbers in JavaScript

JavaScript by Radu TM June 21, 2022

//check if a number is between two numbers in JavaScript
const num = 4;

//if num is greater than or equal to 3 and less than or equal to 5, print "🍏"
if (num >= 3 && num <= 5) {
  console.log("🍏");
}

0

26.005

Javascript range between two numbers

JavaScript by Radu TM May 24, 2022

//es6
console.log(
  Array.from({ length: 5 }, (val, ind) => ind)
)

//also es6
console.log(
  [...Array(5), keys()]
)

0

11.159

Javascript range between two numbers

JavaScript by Radu TM May 24, 2022

const range = (min, max) => [...Array(max - min + 1).keys()].map(i => i + min);
//or
const range = (min, max) => Array.from({ length: max - min + 1 }, (_, i) => min + i);

range(5, 10);
// [5, 6, 7, 8, 9, 10]

0

11.159

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories