2 ms·
Actually, while it's almost never used (I certainly haven't seen code using it), blocks cooperate with labels too. The following is perfectly valid: var fn =
by oinksoft 15y ago
Actually, while it's almost never used (I certainly haven't seen code using it), blocks cooperate with labels too. The following is perfectly valid:
var fn = function() {
nowWeDance: {
dance();
}
};
The block uses the same execution context and scope, of course, so it's not useful.
A block is legal alone too:
(function() {
{
return 1;
}
})(); // 1
I suppose for a very long switch statement (god forbid), blocks could be useful:
switch (x) {
case 1: {
// do stuff
break;
}
case 2: {
// do stuff
break;
}
}
But I wouldn't favor it because it makes the break seem implicit to the reader when it in fact is not.
- deleted 15y ago[deleted]