Skip to content

Instantly share code, notes, and snippets.

@donno2048
Created November 6, 2022 19:40
Show Gist options
  • Save donno2048/c8feadb6953230bfc935b9b025c99d61 to your computer and use it in GitHub Desktop.
Save donno2048/c8feadb6953230bfc935b9b025c99d61 to your computer and use it in GitHub Desktop.
Stupid things in Node.js
// Stupid things in Node.js
NaN == NaN // false
0.1 + 0.2 == 0.3 // false
[] == true // false
!![] == true // true
0 == [] // true
0 == [0] // true
[] == [0] == 0 // true
[] == [0] // false
[] + [] // ''
[] + {} // '[object Object]'
{} + [] // 0
"1" + "2" - "3" == "9" // true
[] == ![] // true
"NaN" + + "foo" // 'NaNNaN'
[4] + [2] // '42'
[1, 2] + [3, 4] // '1,23,4'
typeof NaN // number
9999999999999999 // 10000000000000000
10000000000000000 + 1 // 10000000000000000
try {break} catch {} // This has an error, which sucks
[-3,-2,-1,0,1,2,3].sort() // [ -1, -2, -3, 0, 1, 2, 3 ]
Math.max() // -Infinity
Math.min() // Infinity
(+[]+[]).length // 1
(!+[]+[]).length // 4
["10", "10", "10", "10"].map(parseInt) // [ 10, NaN, 2, 3 ]
Boolean(false) // false
Boolean(new Boolean(false)) // true
[...undefined] // TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
{...undefined} // {}
parseInt(.5) // 0
parseInt(.05) // 0
parseInt(.005) // 0
parseInt(.0000005) // 5
[1]['pop']() // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment