You-dont-know-js: {} + []gives the same as [] + {}, but book reports differently

Created on 29 Mar 2019  路  3Comments  路  Source: getify/You-Dont-Know-JS

Hi, i was going through the types and Grammer , Chapter 5. I found this wrong while executing as a code.
{} + [] gives the same as [] + {} which is "[object Object]", but book reports differently to both the cases.
image

Most helpful comment

hey @getify , thanks for clearing the confusion.@Kiran thanks for the timely response. It is correct

All 3 comments

Chrome console returned this:

js-twik

You put both into a console.log() statement, which makes both of them expressions, so yes they will be the same.

The point of the book section in question is when they're in statement positions (as shown by @KirankumarAmbati), the {} is taken as a separate block statement when it's at the beginning.

hey @getify , thanks for clearing the confusion.@Kiran thanks for the timely response. It is correct

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorendorff picture jorendorff  路  5Comments

aszx87410 picture aszx87410  路  3Comments

madmadi picture madmadi  路  5Comments

mzwae picture mzwae  路  4Comments

ahmedvip2008 picture ahmedvip2008  路  3Comments