hoisting past catch
Peter van der Zee
ecma at qfox.nl
Thu Nov 4 12:00:25 PDT 2010
> On Nov 4, 2010, at 10:32 AM, Peter van der Zee wrote:
>> Shouldn't any var declared in the catch block be locally scoped
>> as well?
> var always hoists to top of function or program. Why would it be
> different in a catch block? It's not in ES3, which standardized
Hrm. After typing the string of events that es should go through for
instantiating a catch clause it dawns to me that it's all after the facts.
Variable statements are parsed when the program or the function is parsed, that
includes those inside catch statements. So even though catch gets its own scope,
the variables are already bound to the nearest function/global scope, not to the
scope Catch gets.
I guess my confusion came from the notion that catch gets its own scope and
thinking variables in catch statements wouldn't get hoisted until the code in
that "scope" was entered. Thanks :)
More information about the es-discuss