1

when run in console:

let b; {b} = {b:1} // run without error

{b} = {b:1} // empty line before this code, and run with error VM243:2 Uncaught SyntaxError: Unexpected token '=' ({b} = {b:1}) // run without error

when run in https://www.typescriptlang.org/play, error message like below:

Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses.

sidaeren
  • 11
  • 1
  • Does this answer your question? [declaration or statement expected javascript/typescript](https://stackoverflow.com/questions/35576307/declaration-or-statement-expected-javascript-typescript) – Lety Aug 17 '22 at 12:12
  • The problem is that `{` is ambiguous for the JavaScript parser since the `{` symbol indicates the beginning of a block. For this reason, you need parenthesis – Christian Vincenzo Traina Aug 17 '22 at 12:18
  • 2
    I don't know what's your question about (I don't see any question), but if you are wondering why, the reason is performance: if the parser had to disambiguate the beginning of a block from the destructuring syntax, it was way slower – Christian Vincenzo Traina Aug 17 '22 at 12:20

0 Answers0