Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Created April 27, 2012 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhanwu/2509189 to your computer and use it in GitHub Desktop.
Save ryanhanwu/2509189 to your computer and use it in GitHub Desktop.
JavaScript Scope Chain - Variable
//JavaScript Scope Chain
var mytxt = 'test1';
function echo() {
console.log("A-->" + mytxt);
var mytxt = 'test2';
console.log("B-->" + mytxt);
}
echo();
/*
The result is not
A-->test1
B-->test2
it's
A-->undefined
B-->test2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment