Input | !Number.isNaN(x) |
!isNaN(x) |
typeof x === 'number' |
isFinite(x) |
Number.isFinite(x) |
Number.isInteger(x) |
Number.isSafeInteger(x) |
---|---|---|---|---|---|---|---|
123 |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
"123" |
✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
NaN |
❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
"NaN" |
✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
"hello" |
✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
"0x123" |
✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
Infinity |
✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
Number.MAX_SAFE_INTEGER + 1 |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
Last active
January 9, 2022 23:18
-
-
Save jonahsnider/91fd46f350b4248dbccc44451e4c7003 to your computer and use it in GitHub Desktop.
Number validation with built-in JS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment