JSFiddle - React, Tailwind, and code Playground

JavaScript

function makeCounter() {
  var currentCount = 1;

  return function() {
    return currentCount++;
  };
}

var counter = makeCounter(); // [[Scope]] -> {currentCount: 1}

alert(counter()); // 1, [[Scope]] -> {currentCount: 1}
alert(counter()); // 2, [[Scope]] -> {currentCount: 2}
alert(counter()); // 3, [[Scope]] -> {currentCount: 3}