I think abusing ASI is a funny hack (and I did it for a while) but the more functional my programming style became the more ran into these cases, so I channeled my inner Douglas Crockford and reopened my bag of semicolons.
Can You Find the Bug in This Code?
21–30 of 64 posts
Re: Can You Find the Bug in This Code?
#22The real bug is the failure to use semi-colons. I literally cannot comprehend the non-use of semi-colons in JS.
If so, the failure lies with the spec. (personally, I like ASI)
"Is the language specification too loose?"
"No, it's the developers who are wrong."
Re: Can You Find the Bug in This Code?
#23I'm not sure I understand why it's wrapped in an enclosing function, though; you can reproduce the error with just:
(() => console.log("Hello"))()
(() => console.log("World"))()Re: Can You Find the Bug in This Code?
#24Earlier quoted context omitted.
I'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.
Always for ( and [ when they start a statement. It really is that simple.
I do agree that good use cases are few and far between.
Re: Can You Find the Bug in This Code?
#25Always prepend ( and [ with ; I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.
Re: Can You Find the Bug in This Code?
#26An even more common use-case that fails without semicolons by T.J. Crowder (2015): http://blog.niftysnippets.org/2015/09/automatic-semicolon-in... There are a number of cases where not having semicolons has its downsides, I'm yet to see a single case of an upside.
It's a signal of coolness from inexperienced programmers. That's the value proposition offered by semicolon-free JS.
Re: Can You Find the Bug in This Code?
#27The real bug is the failure to use semi-colons. I literally cannot comprehend the non-use of semi-colons in JS.
Re: Can You Find the Bug in This Code?
#28Re: Can You Find the Bug in This Code?
#29I refuse to use semi-colons in TS/JS, unless that conflicts with existing code standards. I feel like it's as if I'm using semi-colons in Go. This can easily be avoided by writing clearer code.
Relevant: https://standardjs.com/rules.html#semicolons (hint: no semi-colons!)
;(function () {
window.alert('ok')
}())
Which, just, eww.Just use semicolons. Everywhere, always. Then you can treat JS's parsing rules as the same as every other language, and not normally like every other language except when a line begins with one of a select set of magical charaters that need to be prepended with `;` for unclear reasons.
Just end lines with `;`.