never rely on semi-colon insertion! (unless you like to spend friday evenings hunting bugs, while your colleagues are having fun).
Everybody knows, that:
return
{
x: 1
}
will return undefined, because semicolon will be inserted right after return.
But there are few other illustrative examples (all will throw exceptions):
-
1.----
var foo = 'asdf'
[1,2,3].forEach(function(value){console.log(value)})'asdf'[1,2,3] is syntax error
-
2.----
var foo = 1+2
('asdf' + 'blubb').toUpperCase() '2' is not a function
-
3.----
This code will work:
function(){}
(function(){
})()But this one:
var foo = function(){}
(function(){
})()will throw:
'}
(function(){
})' is not a function
-------
copy/pasted from comment in "grumpy old farts vs dumb emo kids"* thread :
https://github.com/twitter/bootstrap/issues/3057#issuecomment-5140311-------
via:
http://brendaneich.com/2012/04/the-infernal-semicolon/-------
p.s.: * - 'seasoned veterans vs creative youth' would be less offensive, but.. can i at least insult people, more talented than me, if i cant write better code ?