Number.isFinite() is the best way to check for a number in JavaScript

Need a simple way to check for a number in JavaScript, but don’t want NaN or Infinity? Use Number.isFinite() instead of typeof.

Hi Sumer Singh, thanks for taking the time to read my article and for your insightful response!

You are exactly right, Number.isFinite() is the easiest way to check for a finite number, as it excludes NaN, Infinity, and -Infinity:

I clarified my article on checking for a JavaScript number to recommend Number.isFinite() and to point out that there is the global isFinite() function, which does perform type coercion if that behavior is desired:

Thanks again for supporting my blog and sharing your insight!

It is much appreciated!!! 😁

πŸ€“ The physical therapist who writes JavaScript πŸ’ͺ Web Developer 😎 Mentor 🧠 DPT πŸ˜„ SEO Expert 😁 React πŸ˜† Jamstack πŸ’¬ Ask me anything πŸ‘‰ πŸ‘ˆ

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store