Last active
May 6, 2017 03:33
-
-
Save iwek/4575330 to your computer and use it in GitHub Desktop.
JavaScript Nested Function Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to call g()