Created
May 10, 2020 21:23
-
-
Save Nathan-Nesbitt/1e6a354615ce1fda1ede3f6e60d37fbf to your computer and use it in GitHub Desktop.
Function Example JavaScript
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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample code for https://nathan.nesbitt.ca/blog-posts/IntroductionToJavascript.html