0

I ran the following code in turn in Chrome Javascript Console

{f}={f:3} // it created a new variable f with a value of 3
{f}={f:3}; // Uncaught SyntaxError: Unexpected token '='

{f}={f:3} // There is a blank line on it,error: Uncaught SyntaxError: Unexpected token '='

Why do they behave differently?

What I really want to ask is why the bad code run without error in the first case.

The problem extends from here: object_destructuring - Assignment separate from declaration

Neo
  • 11
  • 1
  • 2
    Browser consoles are not a good way to do JavaScript experimentation before you understand how they operate. – Pointy Dec 05 '21 at 14:05
  • 1
    *Especially* not the Chrome console as it tries to add some magic to what you wrote thus giving you mixed results. Like you see by adding `;` - that gives you the *correct* behaviour for the code you had. Chrome was just trying to be helpful and it *lied* to you about what the first piece of code would result in. – VLAZ Dec 05 '21 at 14:17

0 Answers0