0

is it a must to use semicolons after an object literal in js?

this code doesnot work:

          let nameof = "Hey";
          let age = 12
           const obj = {
           nameof: "One",
           age: 12,
           order: function () {
           return this.name;
            },
        }
           ({ nameof, age } = obj);
          console.log(nameof, age)

yet this works when a semi-colon is added at the end of the object literal.

1 Answers1

-2

I think it is needed, otherwise the browser issues this error:

Uncaught ReferenceError: can't access lexical declaration 'obj' before initialization (line 10)

Moreover, my IDE says:

The expression is not callable. If this is not supposed to be a call, check for a missing semicolon

andrewJames
  • 19,570
  • 8
  • 19
  • 51