Skip to content

Instantly share code, notes, and snippets.

@lesleh
Last active September 16, 2018 20:45
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 lesleh/84036b6e7a5be18d9bdd82b4d43df2ce to your computer and use it in GitHub Desktop.
Save lesleh/84036b6e7a5be18d9bdd82b4d43df2ce to your computer and use it in GitHub Desktop.
// Lets say you have a function that creates adders, for adding two numbers
function makeAdder(firstNumber) {
return function(secondNumber) {
return firstNumber + secondNumber;
};
}
let result
const addFive = makeAdder(5);
result = addFive(3);
console.log(result); // 8
// You don't have to assign it to a temporary variable though
result = makeAdder(10)(20);
console.log(result); // 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment