Skip to content

Instantly share code, notes, and snippets.

@danielantelo
Created November 23, 2015 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielantelo/b2e737a6fa4015443c5c to your computer and use it in GitHub Desktop.
Save danielantelo/b2e737a6fa4015443c5c to your computer and use it in GitHub Desktop.
Simple scoping and hoisting js exercise
var foo = 1;
(function() {
console.log(foo);
var foo = 2;
var baz = 3;
bar = 4;
})();
console.log(foo);
console.log(bar);
console.log(baz);
@MuhammadTaimoor795
Copy link

MuhammadTaimoor795 commented Feb 21, 2023

undefined
1
4

@danielantelo
Copy link
Author

danielantelo commented Feb 21, 2023

run it, looks like you will be surprised.

screen1

@MuhammadTaimoor795
Copy link

yes , i got it

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