value === !Infinity actually makes a falsy value

Instead, use !== (strict equality operator) when checking for a finite number.

Dr. Derek Austin 🥳
1 min readJul 31, 2020

--

Hey Алексей, Thanks for reading and responding!

Using the ! operator (the NOT operator) actually invokes truthy and falsy rules in JavaScript. Since Infinity is truthy, then !Infinity will always have a value of false. And your number value would never equal false:

console.log(!Infinity) // false
console.log(3 === !Infinity) // false
console.log(3 !== Infinity) // true

Instead, you want to use !== (the strict equality operator).

Photo by Pawel Janiak on Unsplash

--

--

Dr. Derek Austin 🥳
Dr. Derek Austin 🥳

Written by Dr. Derek Austin 🥳

Hi, I'm Doctor Derek! I've been a professional web developer since 2005, and I love writing about programming with JavaScript, TypeScript, React, Next.js & Git.

No responses yet