Javascript, the weirdo

Published:

JavaScript

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
Please, do not install every shit titleee

I am working on React app with couple of other developers. And you know it, you need this component, that functionality, etc. so you google it, install the package and the work is done. Is it ok to work like this? Do you even know what exactly you added to your project and do you really need it?

Read more
Chaos Ajax - is your application ready to fail? titleee

You are creating an application that shows data to the user - doesn't matter if he is searching for some specific thing or he is only listing everything you have. What happens if the server responds with empty array? Or with error? Will your application show only empty space or an error message?

Read more