JavaScript Closures in Loops: How to Capture the Correct Loop Variable Value | CodeTrail