by jarfil · 6y ago · 0 comments
[1, 2, 3].forEach( ... )
(function(){ ... })()
Statements like that are virtually always errors under ASI, but if you avoid them nothing else causes problems.https://wiki.c2.com/?FixBrokenWindows
https://www.rtuin.nl/2012/08/software-development-and-the-br...
https://blog.codinghorror.com/the-broken-window-theory/
https://medium.com/@matryer/broken-windows-theory-why-code-q...
https://news.ycombinator.com/item?id=3842713
https://github.com/twbs/bootstrap/issues/3057
And don't forget to semicolon-harden your most important mission-critical code:
https://www.bluejava.com/4PN/Semicolons-in-JavaScript---The-...
;;;;;;;;;;;; // protective wall of semicolons
;;var a = 10, b = 20;;
;;
;;function add(a,b)
;;{;;
;;return a + b;;;;;;;; // this function MUST work
;;};;
;;;;;;;;;;;; // protective wall of semicolons var a = []
var b = ''
var c = {}
[].concat.apply(a, [b, c])I don't really understand the drama, just like people who use semis in place you don't need them. In real code, you should be using a linter anyways. At which point semis or no semis becomes purely an aesthetic concern. Like whether you use single or double quotes.
I haven't used semicolons in over 8 years and never had an issue. And with tools like eslint and prettier, you have no excuse to be making such trivial mistakes, like adding superfluous semicolons like function(){};
return
false
Where the program returns undefined. I can only think of these examples as straw men. Not once did I run in to an ASI bug. foo=arr[i]
(counter++) if(foo)
doX()
doY()if(foo) doX() doY();
Intuitively, as a someone who uses C style languages, this becomes:
if(foo) doX(); doY();
Can someone confirm which intuition is correct?
I ask because, to me: it not being intuitive is a problem--even if it is not classified as ambiguous.
It being only contextually intuitive, also seems somewhat problematic--but maybe excusable if it is assumed you know some similar language going into it and it behaves similarly to that other language.