Hacker News new | ask | show | jobs
by sp332 860 days ago
"Any JSON text is a valid JavaScript expression, but only after the JSON superset revision. Before the revision, U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are allowed in string literals and property keys in JSON; but the same use in JavaScript string literals is a SyntaxError."

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

"In fact, since JavaScript does not support bare objects, the simple statement {"k":"v"} will emit an error in JavaScript"

https://medium.com/@ExplosionPills/json-is-not-javascript-5d...

2 comments

> "In fact, since JavaScript does not support bare objects, the simple statement {"k":"v"} will emit an error in JavaScript"

This is kind of a silly, "well technically". Its a valid expression. Its not a valid statement. It is valid javascript in the sense most people mean when asking the question if something is valid javascript.

Eh, this is slightly dated—{"k":"v"} does work in the WebKit and Blink consoles, and the superset proposal was approved, so those separators should work fine too.
The console evaluates what is passed to it as an expression, which is a different context from how scripts or modules are evaluated.