Non-local variable: Difference between revisions

Content deleted Content added
m clean up, typo(s) fixed: Javascript → JavaScript
KZ737 (talk | contribs)
 
(One intermediate revision by one other user not shown)
Line 1:
{{Short description|In computer programming, a variable which is not defined in the local scope}}
 
{{More citations needed|date=January 2025}}
In [[programming language theory]], a '''non-local variable''' is a variable that is not defined in the local [[Scope (computer science)|scope]]. While the term can refer to [[global variable]]s, it is primarily used in the context of [[nested function|nested]] and [[anonymous function]]s where some variables can be in neither the [[local scope|local]] nor the [[global scope]].
 
Line 18 ⟶ 19:
</syntaxhighlight>
 
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>:
<syntaxhighlight lang="javascript">
function outer() {