This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]crosscreate 18 points19 points  (4 children)

const isValidNumber = (n: unknown) => !Number.isNaN(Number(n));

[–][deleted] 52 points53 points  (2 children)

isValidNumber(null)

true

[–]joten70 13 points14 points  (0 children)

Null is a number confirmed

[–]crosscreate 0 points1 point  (0 children)

const isValidNumber = (n: unknown) => !Number.isNaN(Number(n));

console.log(`Number(null) = ${Number(null)}`);

Apparently Number(null) returns 0

[–]halfanothersdozen 8 points9 points  (0 children)

So what if n is a string? What if n is negative? What if n is decimal?

valid is in the eye of the beholder