Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Created April 27, 2016 23:43
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 iam-peekay/77a0b6f1d353142f5ef52bc34c1857f8 to your computer and use it in GitHub Desktop.
Save iam-peekay/77a0b6f1d353142f5ef52bc34c1857f8 to your computer and use it in GitHub Desktop.
var myVar = 100;
function foo() {
console.log(myVar);
}
foo(); // Static scope: 100; Dynamic scope: 100
(function () {
var myVar = 50;
foo(); // Static scope: 100; Dynamic scope: 50
})();
// Higher-order function
(function (arg) {
var myVar = 1500;
arg(); // Static scope: 100; Dynamic scope: 1500
})(foo);
@vpsk-zz
Copy link

vpsk-zz commented Mar 19, 2017

can we console it, static & dynamic scope ??

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