Skip to content

Instantly share code, notes, and snippets.

@amysimmons
Created February 6, 2018 09:10
Show Gist options
  • Save amysimmons/76678600c884aa210b7e697e29ae7398 to your computer and use it in GitHub Desktop.
Save amysimmons/76678600c884aa210b7e697e29ae7398 to your computer and use it in GitHub Desktop.
x = {}
x.valueOf = () => 22
Number(x) // 22

y = []
y.toString = () => '22'
Number(y) // 22

z = {}
z.valueOf() // {} (not a primitive)
z.toString() // "[object Object]" (a string primitive which cannot be coerced to a number)
Number(z) // NaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment