Skip to main content

Javascript, the weirdo

· One min read
Matej Jelluš

Collection of JavaScript examples when it behaves...weird? Funny?

2 + true // => 3

0.1 + 0.2 // => 0.300000000000000004

typeof NaN // => number

'5' - 3 // => 2

'5' + 3 // => 53

'5' - '4' // => 1

'5' + + '5' // => 55

'foo' + + 'foo' // => fooNan

'5' + - '2' // => 5-2

'5' + - + - - + - - + + - + - + - + - - - '-2' // => 52

[] + [] // => ""

[] + {} // => [object Object]

{} + [] // => 0

[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]] // => "123"

null > 0 // => false
null == 0 // => false
null >= 0 // => true

parseInt(0.000001) // => 0
parseInt(0.0000001) // => 1

parseInt(0.000006) // => 0
parseInt(0.0000006) // => 6

Did you like this post? Was it helpful? I am always learning and trying new technologies. When I struggle with something and finally manage to solve it, I share my experience.