Editing JavaScript/Notes/Scope
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 77: | Line 77: | ||
</source --> | </source --> | ||
== Block Scope == | |||
Normally, the only way to create scope in JavaScript is by creating a function. However, a little known anomaly is that the catch block augments the scope with a new object. | |||
<source lang="javascript"> | |||
function x() { | |||
var result = typeof x; | |||
try { | |||
y; | |||
} catch(x) { | |||
x = 10; | |||
result = [result, x]; | |||
} | |||
result.push(typeof x); | |||
alert(result); | |||
} | |||
</source> | |||
== Block Scope == | == Block Scope == | ||
Normally, the only way to create scope in JavaScript is by creating a function. However, a little known anomaly is that the catch block augments the scope with a new object. | Normally, the only way to create scope in JavaScript is by creating a function. However, a little known anomaly is that the catch block augments the scope with a new object. |