1

I know that JavaScript can interpret {} as an empty block instead of an empty object. I don`t know why Node.js REPL (v12.3.1) behaves differently with semicolon and without semicolon.

>{}+{}
'[object Object][object Object]'
>{}+{};
NaN
  • @Li357: I do not believe this is a duplicate. There is some mention about expressions vs. statements deep down in the comments below one of the answers, but nothing that answers this question. – Jörg W Mittag Jun 23 '19 at 11:43
  • Node is aware that the usual `eval` parse is annoying in many cases when using a REPL, and intelligently interprets text like that as an expression. (It didn’t always.) `{}+{};`, however, can never be an expression. – Ry- Jun 23 '19 at 12:44
  • Why isn`t {}+{}; expression? From Google Chrome Console: > {}+{}; <- NaN – Juraj Pecháč Jun 23 '19 at 13:17
  • @JörgWMittag The linked dupe has exactly the same question, why `{}+{}` results in string concat while `{}+{};` becomes NaN. – Andrew Li Jun 23 '19 at 21:48

0 Answers0