Update outer state from a function.

Closure Updates

closure_updates.js
const start = 1;
let count = start;

function nextCount() {
  count += 1;
  return count;
}

const first = nextCount();
const second = nextCount();

console.log("start=" + start);
console.log("first=" + first);
console.log("second=" + second);
closure-updates Closures can read and update outer variables. This is useful, but it also means the function carries state between calls.