Why I try to ALWAYS use semicolons in JS:

In short, weird shit happens sometimes

An example:

So I'm doing a small project for freeCodeCamp, working with the Twitch API. I decided to make an array on the fly to append a few elements to a documentFrag in order after setting all my props. Forgot a semicolon. Apparently, Babel transpiles this:

info.innerHTML = (``)
[span, caret, info].forEach(elm => frag.appendChild(elm));

to this if you omit the semicolon:
info.innerHTML = ' '[(span, caret, info)]

this is why you should avoid relying on ASI, you're going to have to remember them in other languages out there, so for your own sanity, might as well get used to them. Just thought I'd share--who knows, might help a JS newb out there somewhere.

  • 0
    use a linter and you'll have no such problems.
  • 0
    @plusgut i should probably stop ignoring it for real 😂😂😂
  • 0
    @AllenII seriously it helps for real. And if you want consistent coding styles enforced use jscs.
  • 0
    @plusgut I'm "planning" on updating something i did before--moving from pug templates and vanilla ES6 to React. Perfect time to get used to using a linter.
  • 0
    @RavinduL exactly my problem with it, especially that last part
Add Comment