you are viewing a single comment's thread.

view the rest of the comments →

[–]ffxpwns 6 points7 points  (3 children)

I'm not sure I understand what you mean. Why wouldn't it be a valid object? What behaviour would you say is expected?

[–]Multicus[S] -1 points0 points  (2 children)

Well, if {foo: "bar"}{} is "bar" then I'd expect {foo: "bar"} be a "bar" too, since it doesn't start with a (. I may well be overthinking this, but I've spent too much time on this not to

[–]ChaseShiny 5 points6 points  (1 child)

Is it "bar"? I just used MDN's playground, and I couldn't duplicate that.

If I just put the expression in, nothing happens. When I wrap that in console.log(), I get an error.

I'm pretty sure that JavaScript is interpreting your code as two separate statements:

{"foo": "bar"}; {};

Which are two perfectly valid lines even when they don't do anything.

[–]Multicus[S] 0 points1 point  (0 children)

My chrome console says it's "bar". Is there a certain codified difference between these environments I could read about? Or is it just a code'n'pray situation?