Interviews1 answer
How do JavaScript closures work?
1 Answer
Closures are hard to explain because they are used to make some behaviour work that everybody intuitively expects to work anyway. I find the best way to explain them (and the way that I learned what they do) is to imagine the situation without them:
const makePlus = function(x) {
return function(y) { return x y; };
}
const plus5 = makePlus(5);
console.log(plus5(3));
Pranam BhatPosted May 21, 2021, 12:15 PM EDT

