Can't Any Variable Be Made Global by Returning It's Value Within a Function?


#1

Just as the title asks… Can’t any (local) variable be made global by simply returning it’s value within a function? Isn’t return solely for the purpose of using a variable outside of the code block it was originally defined in?

Thank you!


#2

that doesn’t make it a global variable. If we do:

var example = function(){
    var x = "hello world"
    return x
}

console.log(example())

we don’t have any global variable

yep.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.