Created
October 17, 2016 15:39
-
-
Save JoeShep/bb27fe826020042c531bc1cfa83fe04e to your computer and use it in GitHub Desktop.
Functions intro
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
// Performs an action, but caluculates/returns no value | |
// console.log(returnNothing()); | |
var returnNothing = function() { | |
console.log("I don't return anything"); | |
}; | |
// returnNothing(); | |
// Does a task and returns the result of that task | |
var result = addStuff(); | |
function addStuff() { | |
var sum = 2+2; | |
return sum; | |
console.log("sum?", sum); | |
} | |
// console.log("result", result); | |
// Does a task with data we provide to it via the arguments | |
function add (one,two) { | |
return one + two; | |
} | |
// var result = add("hello", " brave new", " world"); | |
// console.log("Add with args", result ); | |
function subtract (one, two) { | |
return one - two; | |
} | |
// functions can take other functions as an argument. Whaaaat? | |
function performAction (numberOne, numberTwo, action) { | |
var meDone = action(numberOne, numberTwo); | |
return meDone; | |
} | |
var addResult = performAction(1, 2, add); | |
var subtractResult = performAction(1, 2, subtract); | |
console.log("addResult", addResult); | |
console.log("subtractResult", subtractResult); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment