Non-local variable: Difference between revisions

Content deleted Content added
m Reverted 1 edit by 49.126.255.206 (talk) to last revision by Cedar101. (TW)
style refactor
Line 18:
In Javascript, the locality of a variable is determined by the closest <code>var</code> statement for this variable. In the following example, <code>x</code> is local to <code>outer</code> as it contains a <code> var x</code> statement, while <code>inner</code> doesn't. Therefore, x is non-local to <code>inner</code>:
<source lang=javascript>
function outer() {
var x = 1;
function inner() {
x += 1;
console.log(x);