A silly debate that rages just as hard as “tabs vs spaces” is “semicolons or not” in JavaScript. Generally, the answer is “use an automatic formatting tool so you don’t have to think about it”. But if you happen to be on the “no semicolons” side, it’s interesting to note that it can cause confusing bugs sometimes. Thomas Steiner found a fun one:
console.log()
(function(){})
Code language: JavaScript (javascript)
Just a little log statement followed by an IIFE, right? Click over to see what actually happens.
If you do return & then a newline with your return value, you also get an issue of returning nothing. You need to be aware of ASI’s rules regardless—which is why IIFEs have prefixed with ;(function… for the longest time as an ad-hoc ‘standard’. Once you know the rules, you may as well omit those extra characters except where needed, like here.