Looking for JavaScript wizard's help here! Why is this code valid: [{"key":"value"}] x = {"key":"value"} {key:'value'} But this isn't? {"key":"value"} Why is only the object notation invalid when the value is not assigned?
-
Show this thread
-
It seems like it's valid in
@googlechrome but not in@firefox !1 reply 0 retweets 1 likeShow this thread -
This is getting more interesting!
@googlechrome considers it to be an object creation, while@firefox seems to consider it a new block I'll have to dig into the Ecma specs to figure out if there is a spec for it!pic.twitter.com/lnFVskhJIW
1 reply 0 retweets 2 likesShow this thread -
@MicrosoftEdge behaves the same as Firefox, therefore the {"key":"value"} syntax is invalid. Anyone wants to test on an OSX device for Safari?1 reply 0 retweets 1 likeShow this thread -
Antony Garand Retweeted Matt
Solved! As per this tweet: https://twitter.com/r0x33d/status/1062227343350083584 … Non-chrome devices consider the {key: "value"} like a block containing a labeled statement, and not an object creation! This is why it works without quotes, it isn't an object creation.
Antony Garand added,
1 reply 0 retweets 1 likeShow this thread
Mathias Bynens Retweeted Mathias Bynens
No, Chrome behaves like the others here. The exception is in DevTools, where we wrap your input code precisely to make this work. DevTools is not a reliable way to test this syntax.https://twitter.com/mathias/status/1062968728868909057 …
Mathias Bynens added,
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.