I saw this javascript things in a meme

1: [] + [] == "" Why?

2: [] + {} == [object Object] Why?

3: 90+"1" is equal to string "91" - But 90 - "1" why it equal to integer 90 ?

4: 0.5 + 0.1 == 0.6 true But 0.1 + 0.2 == 0.3 false Why?

5: {} + [] == 0 Why?

6: (! + [] + [] + ![]).length == 9 Why?

7: 9999999999999999 == 10000000000000000 How?

This might help: https://www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/

you can’t use + with arrays so they are converted to strings, so you get an empty string from empty arrays

same as above, just the empty object converted to string becomes [object Object]

So, + can be both a number or string operator, with 90 + '1' as you have a string in there, everything becomes string, and the result is "901", instead - is only a number operator, so with 90 - '1' everything is converted to numbers, and it makes 90

floating numbers math. look this:

I’m going with this:

because (! + [] + [] + ![]) evaluates as 'truefalse'
why?

let’s take it in steps
! flips the boolean value of what it has after
+[] evaluatest to 0
so !+[] makes true

so now we have true + []
everything is converted to string, so it becomes "true"

now there is "true" + ![]
the empty array is a truthy value, so flipping its boolean value make it false
so there is "true" + false which becomes "truefalse", and has nine characters

above a certain value there is the same issue than with decimals, precision is lost because there are not enough bits available to use
so there you need to use BigInt data type

Example 4 is just wrong, as 0.5 + 0.1 != true. To make it fit the context it should be this way:

0.7 + 0.3 == true;
0.7 + 0.2 + 0.1 == false;

Certain value being Number.MAX_SAFE_INTEGER :slight_smile: As naming suggests going above in not safe

I edit my mistake above.

I checked it and the console says
image

but yeah, your example makes more sense in seeing the issue
image

(edit: ok, I saw the issue…)

Annotation 2020-08-07 191014
I try in my console.

0.2+0.1 == 0.3
why this equation give me false.

Try just 0.2 + 0.1 and see the video about floating point numbers @ilenia suggested