I have this Javascript code, which works as expected:
This is because you aren't capturing the value of i from the for-loop. You can tweak your code to this to make it work:
var timeInterval = 1000;
for (var i = 0, l = 2; i < l; i++ ) {
(function(i2, timeInterval2) {
setTimeout(function() {
$(".test").append("test" + i2);
}, timeInterval2);
})(i, timeInterval);
timeInterval += 1000;
}