{
  "id": "enwiki-001310963400",
  "slug": "non-local-variable",
  "title": "Non-local variable",
  "qid": "",
  "lead": "In programming language theory, a non-local variable is a variable that is not defined in the local scope. While the term can refer to global variables, it is primarily used in the context of nested and anonymous functions where some variables can be in neither the local nor the global scope. In Lua they are called the upvalues of the function. == Examples == === Nested functions === In the Python 3 example that follows there is a nested function inner defined in the scope of another function outer . The variable x is local to outer , but non-local to inner (nor is it global): from typing import Callable def outer() -> Callable[[], None]: x: int = 1 def inner() -> None: nonlocal x x += 1 print(x) return inner In JavaScript, the locality of a variable is determined by the closest var statement for this variable. In the following example, x is local to outer as it contains a var x statement, while inner doesn't. Therefore, x is non-local to inner : function outer() { var x = 1; function inner() { x += 1; console.log(x); } return inner; } === Anonymous functions === In the Haskell example that follows the variable c is non-local in the anonymous function \\x -> x + c : outer = let c = 1 in map (\\x -> x + c) [1, 2, 3, 4, 5]",
  "body": "In programming language theory, a non-local variable is a variable that is not defined in the local scope. While the term can refer to global variables, it is primarily used in the context of nested and anonymous functions where some variables can be in neither the local nor the global scope. In Lua they are called the upvalues of the function. from typing import Callable def outer() -> Callable[[], None]: x: int = 1 def inner() -> None: nonlocal x x += 1 print(x) return inner In JavaScript, the locality of a variable is determined by the closest var statement for this variable. In the following example, x is local to outer as it contains a var x statement, while inner doesn't. Therefore, x is non-local to inner : function outer() { var x = 1; function inner() { x += 1; console.log(x); } return inner; } outer = let c = 1 in map (\\x -> x + c) [1, 2, 3, 4, 5] ==Notes==",
  "categories": [
    "23110049",
    "23118434",
    "23603337",
    "24043274",
    "50701333",
    "58618099"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1310963400",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1757683972.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001310963400",
    "type": "webpage",
    "title": "Non-local variable",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/non-local-variable",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          20
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          20
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001310963400",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1310963400",
    "note": "Immutable snapshot enwiki-001310963400"
  }
}