How does a function in a loop (which returns another function) work? [duplicate]
When you assign the function to the click handler, a closure is created. Basically a closure is formed when you nest functions, inner functions can refer to the variables present in their outer enclosing functions even after their parent functions have already executed. At the time that the click event is executed, the handler refers … Read more