Skip to content

Instantly share code, notes, and snippets.

@getify
Last active February 27, 2023 03:04
Show Gist options
  • Save getify/a9afbf1d23a5c51efe158888b88ba63e to your computer and use it in GitHub Desktop.
Save getify/a9afbf1d23a5c51efe158888b88ba63e to your computer and use it in GitHub Desktop.
example of closure?
function A() {
var x = 1;
C(B);
function B() { console.log(x); }
function C(callback) {
B === callback; // true
B(); // is this console.log() using a closure or not? depends on perspective.
callback(); // ditto
}
}
A();
// 1
// 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment