Skip to content

Instantly share code, notes, and snippets.

@arieljatib
Last active October 10, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arieljatib/5558f6e9357cb9e77b47 to your computer and use it in GitHub Desktop.
Save arieljatib/5558f6e9357cb9e77b47 to your computer and use it in GitHub Desktop.
JavaScript : The Return
// You can set a variable to a function like this:
function myFunc(){
var foo= 500;
// foo is declared inside the function so it cannot be accessed outside of the function.
return foo;
}
var a = myFunc();
console.log(a); //500
// If you declare the variable outside the function, you can then change the value inside the function, like so:
var foo = 0;
function myFunc(){
foo= 500;
}
myFunc();
console.log(foo); //500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment