Skip to content

Instantly share code, notes, and snippets.

@matthewbeta
Last active February 23, 2017 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbeta/9c0fd025cc6c90d1d8616cd3538dbcb2 to your computer and use it in GitHub Desktop.
Save matthewbeta/9c0fd025cc6c90d1d8616cd3538dbcb2 to your computer and use it in GitHub Desktop.
Test if its a number in JS
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