Last active
February 23, 2017 17:52
-
-
Save matthewbeta/9c0fd025cc6c90d1d8616cd3538dbcb2 to your computer and use it in GitHub Desktop.
Test if its a number in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNumber(val) { | |
// only returns true if its a number | |
return Number(val) === val; | |
} | |
// OR | |
function isAlsoNumber(val) { | |
return typeof val === 'number' && !Number.isNaN(val) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment