0

this is the code:

let result

if (session.isLegacy) {
    result = await session.onWhatsApp(jid)
} else {
    ;[result] = await session.onWhatsApp(jid)
}

He defined the result inside square brackets, and semicolon on the left side

I know the Destructuring, but why put the semicolon on the left side?

Zulfikar Ahmad
  • 407
  • 1
  • 7
  • 18
  • 1
    Covered by [What are the rules for JavaScript's automatic semicolon insertion (ASI)?](/a/73702481/4642212). Whoever wrote this is just being overly cautious at the expense of readability. It’s to prevent code like `someStatement` ⟨line break⟩ `[ x ] = y` to be misinterpreted as `someStatement[x] = y`. However, the much more readable alternative is to _always_ put a semicolon at the _end_. (It doesn’t matter where exactly the semicolon is placed, though; putting it at the start is not parsed in a special way.) – Sebastian Simon Dec 30 '22 at 07:22

0 Answers0