JavaScript is awesome. It’s pretty popular, so many people agree. But JavaScript can also be pretty weird. Like coming up with a good comparison. It seemed like a good idea at first, but as soon as you write it, it gets weirder and weirder. Eventually you remove it again.

So lets quickly move to some JavaScript weirdness.

Like this: `0.1 + 0.2` = Test live

What happens if you print this out? You get this: 0.30000000000000004

Well that is a floating point issue, where precision is limited. This can happen in other programming languages as well.

Try some of these too:

As you can see, JavaScript tries to convert values to one for that specific context. Because the ‘truthy’ value of true is 1, you can actually do calculations.

`![] + [];` = Test live

It returns false, but as a string! That’s because JavaScripts detects an addition operation between these two arrays and converts both values to their primitive values. Which is done with the .toString() method. Because arrays are truthy, the first value is false. Then this is converted to a string (try false.toString()) = “false”
Like this:

``````1. ![] + []
2. false + []
3. "false" + ""
``````

Now this `+[]` = (Test live) converts an array into a number, which is 0.

Now with this knowledge and because we can use a string similar to an array (e.g. `'false' = 'f'`), we can create something beautiful like this: 😎

``````let hello =
([] + ![])[+[]] +
([] + !![])[+!![]] +
([![]] + [][[]])[+!+[] + [+[]]] +
([!![]] + [][[]])[+!+[] + [+!![]]] +
([][[]] + [])[!![] + ![]] +
([!![]] + !+[] + [][[]])[+!+[] + [+[]]];
console.log(hello);
``````