Consider following codes:
try{
throw undefined;
}
catch(someVariable){
someVariable = 10;
// do whatever you want with someVariable
// someVariable will not be a global object at all. (without help of any function scope)
}
// someVariable is no longer valid here
Why some people use this syntax instead of functions when they don't want to declare global variables?
Additional notes:
I've seen this syntax a lot, but the most important one is Google traceur
try {
throw undefined;
} catch (a) {
a = 10;
}
that it is generated because of the following ecma script 6 syntax:
{
let a = 10;
}
Google traceur is a ECMA Script 6 parser on older browsers that currently have no support for new JavaScript features.