Created
May 31, 2016 04:14
-
-
Save imcodingideas/26a4557d5c9402ec44df8f4bff0b40ef to your computer and use it in GitHub Desktop.
javascript scope on http://nodeschjavascript scope on http://nodeschool.io/ scope exersise for a user on reddit https://www.reddit.com/r/learnjavascript/comments/4lt3yf/help_javascript_scope_not_as_expected_what/ool.io/ scope exersise
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
var a = 1, b = 2, c = 3; | |
var start = (function firstFunction(){ | |
var b = 5, c = 6; | |
var obj = {}; | |
obj.firstFunction = function () { | |
return c; | |
}; | |
(function secondFunction(){ | |
var b = 8; | |
obj.secondFunction = function(){ | |
return b; | |
}; | |
(function thirdFunction(){ | |
var a = 7, c = 9; | |
obj.thirdFunction = function(){ | |
return c; | |
}; | |
(function fourthFunction(){ | |
var a = 1, c = 8; | |
obj.fourthFunction = function(){ | |
return c; | |
}; | |
})(); | |
})(); | |
})(); | |
return obj | |
})(); | |
console.log("a: " + a + ", b: " + start.secondFunction() + ", c: " + start.firstFunction()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment