This gist is about Javascript perpective from Programming Language Consept.
Last active
November 21, 2016 09:13
-
-
Save molcay/48959082a6b43e20ed387369d4a2d8c3 to your computer and use it in GitHub Desktop.
Javascript Notes
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
"Scope" | |
" | |
Q: Give the console output of the following code snippet. Recall that, in Javascript var keyword creates a new local variable in the current scope: | |
" | |
var x=1, y=2, z=3; | |
function f() { | |
var y = 4; | |
z = 5; | |
console.log("f1", x, y, z) | |
g(x,y) | |
console.log("f2", x, y, z) | |
h(11,12); | |
console.log("f3", x, y, z) | |
} | |
function g(a,b) { | |
var x = 6; | |
console.log("g1", x, y, z); | |
function h(y,z) { | |
console.log("h1", x, y, z); | |
x = 7; | |
z = 8; | |
console.log("h2", x, y, z); | |
} | |
h(y,z); | |
console.log("g2", x, y, z); | |
} | |
function h(y,z) { | |
console.log("h3", x, y, z); | |
x = 9; | |
z = 10; | |
console.log("h4", x, y, z); | |
} | |
console.log("global", x, y, z) | |
f() | |
console.log("global", x, y, z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment