My primary programming language is LUA, but recently I've been trying to work on a project in JavaScript with the help of a friend. However, I'm confused as to why this loop keeps exceeding the call stack.
var myVar;
(function loop() {
for (var x = 0, ln = 3; x < ln; x++) {
myVar = setTimeout(function(i) {
console.log(i);
}, x * 333, x);
clearTimeout(myVar);
}
loop();
}());