Last active
December 24, 2015 00:40
-
-
Save pamelafox/6718591 to your computer and use it in GitHub Desktop.
A surprising use of JS
This file contains hidden or 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
// Pop quiz! | |
// 1. What will x and y be in this code? | |
(function() { | |
var x = 5; | |
var y = 10; | |
var coordinates = x, y; | |
console.log('First'); | |
console.log(x); | |
console.log(y); | |
})(); | |
// 2. And what about in this code? | |
(function() { | |
var x = 5; | |
var y = 10; | |
function makeCoords() { | |
var coordinates = x, y; | |
console.log('Second'); | |
console.log(x); | |
console.log(y); | |
} | |
makeCoords(); | |
})(); | |
// Now check your answers in repl.it! | |
// Finally, what do you think a new programmer thought would happen, when they wrote line 19? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can rewrite the first one as -
And, the second one as -
IMO, If you teach someone
hoisting
andscope
then (s)he should be able to figure it out 😄