angel,

Automatic Semicolon Insertion (ASI) has (sadly) been a part of JavaScript longer than 2016. I’m not sure exactly when it was introduced, but this document from 2009 already contains it: web.archive.org/web/…/ELS5_Section_7.htm#Section_…

IMO it’s bad practice to rely on ASI since the semicolons may not get inserted where you expected them to. The following snippet


<span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">x </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">y </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">x
</span><span style="color:#323232;">[</span><span style="color:#0086b3;">1</span><span style="color:#323232;">, </span><span style="color:#0086b3;">2</span><span style="color:#323232;">, </span><span style="color:#0086b3;">3</span><span style="color:#323232;">].forEach(console.log) 
</span>

is interpreted as


<span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">x </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0</span><span style="color:#323232;">;
</span><span style="font-weight:bold;color:#a71d5d;">const </span><span style="color:#323232;">y </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">x[</span><span style="color:#0086b3;">1</span><span style="color:#323232;">, </span><span style="color:#0086b3;">2</span><span style="color:#323232;">, </span><span style="color:#0086b3;">3</span><span style="color:#323232;">].forEach(console.log);
</span>

which raises a TypeError.

There are more examples of ASI not doing the right thing on the web, so I don’t agree with “Javascript doesn’t need semicolon”.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • Ask_kbincafe
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines