0

In chrome console (v. 55.0.2883):

{} + {}
"[object Object][object Object]"

but

{} + [] 
0

{} + {} == "[object Object][object Object]"
false

Why in first case chrome takes first braces as an object instead of empty block? Some new es6 feature?

I know about this. In my case the behavior is different

Community
  • 1
  • 1
xaser
  • 29
  • 3
  • 1
    Why? Because JavaScript. – dabadaba Dec 17 '16 at 09:18
  • It has nothing to do with that discussion ({}+{}==NaN). In first case the behavior is different – xaser Dec 17 '16 at 09:25
  • Chrome is probably [dumping some other values](https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference?utm_source=dcc&utm_medium=redirect&utm_campaign=2016q3#0-4). Try `x={}+[]` – sabithpocker Dec 17 '16 at 09:27
  • 4
    Who cares, really? – Niet the Dark Absol Dec 17 '16 at 09:33
  • *"Some new es6 feature?"* No. It's a Chrome specific thing. Depending on your input it tries to determine whether you meant to write an expression or statements. The console (input and output) is not standardized. E.g. `{;}+{}` returns `NaN` (not a syntax error). – Felix Kling Dec 17 '16 at 09:38
  • See also: [wat](https://www.destroyallsoftware.com/talks/wat). – L3viathan Dec 17 '16 at 09:59
  • @dabadaba No. Because Chrome, which does some dark magic under the hood to confuse people. – Oriol Dec 17 '16 at 10:08
  • @FelixKling—also in Safari and Opera. It's answered in the dup I linked in a comment by hugomg and linking to [*What is \[\] + \[\] in javascript*](http://stackoverflow.com/questions/9021109/what-is-in-javascript/9021351#9021351). I've reopened the question, but I still think it's a duplicate. @Oriol—I think it's two legitimate ways to interpret the same bit of code. – RobG Dec 17 '16 at 10:09

0 Answers0