denysdovhan / wtfjs

🤪 A list of funny and tricky JavaScript examples
http://bit.ly/wtfjavascript
Do What The F*ck You Want To Public License
34.97k stars 2.55k forks source link

NaN and undefined in left-hand side expressions, and some Number.NaN stuff #84

Closed 0joshuaolson1 closed 3 years ago

0joshuaolson1 commented 6 years ago
NaN++ // NaN
0/0 // NaN
(0/0)++ // invalid lhs, but [0/0][0]++ works of course
NaN = void 0 // undefined
--undefined // NaN
--void 0 // invalid lhs

Bonus fun with the read-only Number.NaN property:

Object.is(Number.NaN, Number.NaN) // true
Object.is(Number.NaN, NaN) // true
Object.is(NaN, NaN) // true
Number[NaN] // NaN
Number = {NaN: 0} // works in browsers (modifies window.Number), but reassigning Number crashes Node.js v10.2.0 with "TypeError: Number.isSafeInteger is not a function"
Number.NaN // 0
Number.NaN = 1 // 1
Number.NaN // 1