Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Created September 19, 2019 21:27
Show Gist options
  • Select an option

  • Save djD-REK/2943df49900568cbc8f4e99a318e4ffd to your computer and use it in GitHub Desktop.

Select an option

Save djD-REK/2943df49900568cbc8f4e99a318e4ffd to your computer and use it in GitHub Desktop.
console.log(typeof 37) // "number"
console.log(typeof 2.71828) // "number"
console.log(typeof Math.E) // "number"
console.log(typeof Infinity) // "number"
// The typeof NaN is "number" even though NaN means "Not-A-Number":
console.log(typeof NaN) // "number"
// Calling Number explicitly is one way to parse a number:
console.log(typeof Number(`1`)) // "number"
// The parseInt and parseFloat functions are other ways to parse:
console.log(typeof parseInt(`100`)) // "number"
console.log(typeof parseFloat(`100.01`)) // "number"
// Parse failures lead to NaN, and NaN poisons other math:
console.log(typeof (2 * parseInt(`invalid`))) // "number"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment