Last active
November 21, 2018 11:04
-
-
Save harrisonmalone/0b177232892774d5b6221d7e4f96c94f to your computer and use it in GitHub Desktop.
excellent test for scope and the way javascript works
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
function getDemo(demo) { | |
const test = function() { | |
return demo + ' my friend' | |
} | |
// an anonymous function is assigned to a variable test | |
demo = demo + ' how are you' | |
// we do some string concatenation | |
// => "hi how are you" | |
return test() | |
// we return test() which invokes the function, as javascript goes from inner to outer scope demo within this function is "hello how are you" and it's concatenated with " my friend", this value is returned | |
} | |
console.log(getDemo("hi")) | |
// function is called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment