Answers for "what is closures in javascript and why do we use it"

1

closure example

const add = (function () {
  let counter = 0;
  return function () {counter += 1; return counter}
})();

add();
add();
add();

// the counter is now 3
Posted by: Guest on January-31-2022

Code answers related to "what is closures in javascript and why do we use it"

Code answers related to "Javascript"

Browse Popular Code Answers by Language