Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 469 Bytes

007_0_closures.md

File metadata and controls

27 lines (18 loc) · 469 Bytes

Closures

They give us access to an outer function's scope from an inner function.

More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures

function createFunction() {
  const num = 1;
  
  function increaseNumber(numberToIcrease) {
    return num + numberToIcrease;
  }
  
  return increaseNumber;
}

const cf = createFunction();

const increaseWith3 = cf(3);
console.log(increaseWith3); // 4