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

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).

Leave a Comment