JSFiddle - React, Tailwind, and code Playground

by guyluchenbill

JavaScript

function makeAddFunction(amount) {
  
  function add(number) {
    return number + amount;
  }
    
  return add;

}

var addTwo = makeAddFunction(2); 
var addFive = makeAddFunction(5); 
console.log(addTwo(1) + addFive(1));

//so as this works as I see it: 
//addTwo(1) will call makeAddFunction(amount = 2) { } so number = 0 amount = 2
//add is returned and then 1 is passed into makeAddFunction, 
//at this point amount is updated to 3? 
//number is never being used is always 0?