Skip to content

Instantly share code, notes, and snippets.

@iwek
Last active May 6, 2017 03:33
Show Gist options
  • Save iwek/4575330 to your computer and use it in GitHub Desktop.
Save iwek/4575330 to your computer and use it in GitHub Desktop.
JavaScript Nested Function Example
function f() {
var z = 1;
function g(y) {
alert(y + z);
}
g(2);
}
f();// calls f and alerts 3
g(2); //ReferenceError: g is not defined
alert(z); //ReferenceError: z is not defined
var x = f; // f is a reference to the function, and now x is too
x(); // calls f or x, it's the same thing, and alerts 3
@ranjith435
Copy link

how to call g()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment