Skip to main content

Javascript, the weirdo

· One min read
Matej Jelluš
Tech leader and IT nerd who is constantly trying new things, sharing his experiences and still enjoys writing code in his free time. Currently looking for new challenges and opportunities.

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

Do you like this post? Is it helpful? I am always learning and trying new technologies, processes and approaches. When I struggle with something and finally manage to solve it, I share my experience. If you want to support me, please use button below. If you have any questions or comments, please reach me via email juffalow@juffalow.com.

I am also available as a mentor if you need help with your architecture, engineering team or if you are looking for an experienced person to validate your thoughts.