Logo

dev-resources.site

for different kinds of informations.

isNaN vs Number.isNaN

Published at
9/3/2024
Categories
javascript
ts
node
programming
Author
otumianempire
Categories
4 categories in total
javascript
open
ts
open
node
open
programming
open
Author
13 person written this
otumianempire
open
isNaN vs Number.isNaN

Let's skip all that... and get to the point. I like using Number.isNaN but today, it seemed, I learnt why I choose it.

isNaN and Number.isNaN almost seems the same and they are both used to check if a value is NaN. We usually do this when we cast or want to cast some value to a number. When do you use these?

Use isNaN when you want to know if a value is numeric. Examples: "12", "2e4", etc are all numeric strings. If we want to check that such values are numeric, isNaN is best.

Use Number.isNaN when you specifically want to know if the value you are dealing with is NaN.

isNaN first converts the value to number and compares it to NaN, Number(value) === NaN.

This should summarize it:

> isNaN("hello")
true
> Number.isNaN("hello")
false
> Number.isNaN(parseInt("hello"))
true
Enter fullscreen mode Exit fullscreen mode

Check out this article from MDN

ts Article's
30 articles in total
Favicon
How to improve the Frontend part of the project using one button as an example :))))
Favicon
Azure App Service doesn't returned compressed (gzip) files for Angular application?
Favicon
Deploying a Simple Static Website on AWS with CDK and TypeScript
Favicon
Understanding Next.js and TypeScript Tutorial
Favicon
🛠️📚 Classes with TypeScript - a cheat sheet
Favicon
Event Loop in 2 Minutes
Favicon
How Boring It Is to Write Articles or Talk to Certain Types of Developers These Days.
Favicon
How ts-pattern can improve your code readability?
Favicon
isNaN vs Number.isNaN
Favicon
🛠️ 📦 TypeScript Generics - a cheat sheet
Favicon
TypeScript Generics: How to Write Flexible and Type-Safe Code
Favicon
Introduction to TypeScript
Favicon
Dominando os Utility Types do TypeScript
Favicon
Nega aynan Vue.js ?
Favicon
TS-BoilerplateX
Favicon
What Are Standalone Components Angular 17 ?
Favicon
Navigating the JS TS Limbo
Favicon
Demystifying TypeScript Generics with Simple Examples
Favicon
Typescript enum vs. "as const"
Favicon
Mastering TypeScript: A Comprehensive Tutorial
Favicon
m3u8 to mp4 with merged audio
Favicon
Shouldn't an NPM package that helps hundreds of thousands of programmers increase their productivity tenfold be open-sourced?
Favicon
ChatGPT: how I used it to convert HTTP requests to OpenAPI document
Favicon
Cleaning up unused Typescript Files with `ts-prune`
Favicon
Intern's Guide Chat GPT Full Stack: Nest, React, Typescript
Favicon
Using LiteFS with Bun on Fly.io
Favicon
Know your users' location in React Ts
Favicon
Regex #1: Understanding Regex, Regex-Based String Methods and Regex Flags
Favicon
The Witcher Card Game Live
Favicon
Powerful File System manager for Nodejs

Featured ones: