by pvillano · 2y ago · 0 comments
{a:1}["a"] evaluates to ["a"]
but ({a:1}["a"]) evaluates to 1?
It looks bad, but it never comes up in practice because {a:1} is only parsed as a block if it's at the start of a line, which it never would be.
{ // start block statement
a: // labeled statement [1]
1 // expression statement
} // end block statement
[ // start array literal
“a” // string value
] // end array literal
vs. ( // start expression statement
{ // start object literal
a: // object literal key
1 // expression statement
} // end object literal statement
[ // begin subscript property access
“a” // string (property key)
] // end subscript property access
) // end expression
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
versusEdit: fixed second example (it did not match the parent comment), changed some verbiage
If that’s not correct you can provide a counter example