1

If we open the console in Firefox and put:

{
  test: 'test',
  test: 'testtest'
}

Firefox would treat it as a block of code which would turn out to have an error due to unexpected colon. In the opposite Node repl and eg. Chrome interpret it as object declaration. I would say this is a bug but I don't know if I can say that - interpreting it as a block of code is somehow correct? Putting that declarations into another parens i.e. ({...}) works without any problem though but still it's misleading as other environments find out this is an object declaration

ThaFog
  • 493
  • 3
  • 15
  • 1
    It's the opposite. It's Chrome who is "cheating" here - if you type in `{}` it's actually evaluating `({})`. If you evaluate `({})` in FF you'll get the same result. – VLAZ Dec 04 '19 at 15:53
  • so you mean that whole V8 is cheating here? I.e., Node.js' repl also treats it as object – ThaFog Dec 04 '19 at 15:55
  • Yes. It's implicitly wrapping your code in `(` and `)` which will force to evaluate it as expression, thus `{` is not going to be treated as the start of a code block. – VLAZ Dec 04 '19 at 15:56
  • There's no "cheating". There's UX choices. Chrome, Node, Safari choose one thing, Firefox choose another. I prefer the one 3 projects choose to the one 1 project choose – gman Dec 04 '19 at 15:56
  • Sad that it's not generalized in any way - it's not a big thing but still misleading though – ThaFog Dec 04 '19 at 15:58
  • OK, found the question that talks about this behaviour. @gman these three all use V8 as the engine, right? Or am I misremembering about Safari. So the three "chose" to use the engine which made the choice for them – VLAZ Dec 04 '19 at 15:59
  • Yeah, @VLAZ thanks - that explains the approach of Chrome – ThaFog Dec 04 '19 at 15:59
  • @VLAZ, Safari does not use V8 it uses [JavaScriptCore](https://trac.webkit.org/wiki/JavaScriptCore). BTW: Edge and IE print `Expected ';'` so we have 3 different behaviors – gman Dec 04 '19 at 16:01

0 Answers0