Filip Haglund Filip Haglund - 10 months ago 51
Javascript Question

Why is {} + {} no longer NaN in Chrome console?

I noticed today that Chrome 49 no longer outputs

when you type
into the console. Instead it outputs the string
[object Object][object Object]

Why is this? Did the language change?

Answer Source

Chrome devtools now automatically wrap everything that begins with { and ends with } in an implicit pair of parentheses (see code), to force its evaluation as an expression. That way, {} creates an empty object now. You can see this if you go back through the history (), the previous line will be contained in (…).

Why? I don't know, but I could guess it reduces confusion for newbies that don't know of the block-vs-object-literal thing, and it's also more helpful if you just want to evaluate an expression.

And in fact that's the reasoning, as discussed in bug 499864. Pure convenience. And because node REPL had it as well (see code).