Every JavaScript developer must know what a closure is. During a JavaScript coding interview there’s a good chance you’ll get asked about the concept of closures.

I compiled a list of 7 interesting and increasingly challenging questions on JavaScript closures.

Take a pencil and a piece of paper, and try to answer the questions without looking at the answers, or running the code. In my estimation, you would need about 30 minutes.

Have fun!

Questions 1: Closures raise your hand

Consider the following functions clickHandlerimmediate, and delayedReload:

let countClicks = 0;
button.addEventListener('click', function clickHandler() {
  countClicks++;
});
const result = (function immediate(number) {
  const message = `number is: ${number}`;
  return message;
})(100);
setTimeout(function delayedReload() {
  location.reload();
}, 1000);

#javascript #closure #interview

7 Interview Questions on JavaScript Closures. Can You Answer Them?
1.25 GEEK