Skip to content

Instantly share code, notes, and snippets.

@JoeShep
Created October 17, 2016 15:39
Show Gist options
  • Save JoeShep/bb27fe826020042c531bc1cfa83fe04e to your computer and use it in GitHub Desktop.
Save JoeShep/bb27fe826020042c531bc1cfa83fe04e to your computer and use it in GitHub Desktop.
Functions intro
// 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