Skip to content

js closures

Mat Forsberg edited this page · 4 revisions
Clone this wiki locally

Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure 'remembers' the environment in which it was created.

function makeFunc() {
  var name = "Mozilla";
  function displayName() {
    alert(name);
  }
  return displayName;
}

var myFunc = makeFunc();
myFunc();

See MDN

tags: closure, javascript, js

Something went wrong with that request. Please try again.