Skip to content

Instantly share code, notes, and snippets.

@Nathan-Nesbitt
Created May 10, 2020 21:23
Show Gist options
  • Save Nathan-Nesbitt/1e6a354615ce1fda1ede3f6e60d37fbf to your computer and use it in GitHub Desktop.
Save Nathan-Nesbitt/1e6a354615ce1fda1ede3f6e60d37fbf to your computer and use it in GitHub Desktop.
Function Example JavaScript
// A function with no parameters and no return value
var myFunction = function() {
console.log("foobar");
}
// Calling the function //
myFunction();
// A function with 1 parameter and no return value
var myFunction2 = function(variable) {
console.log(variable);
}
// Calling the function //
myFunction2("Programming is cool");
// A function with 2 parameters and a return value
var myFunction3 = function(variable, variable2) {
console.log(variable + variable2);
return variable + variable2;
}
var var1 = 10;
var var2 = 20;
// Calling the function and handling the return value //
var var3 = myFunction3(var1, var2);
// Printing out the return value from the last function //
console.log(var3);
@Nathan-Nesbitt
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment