Weird things happen when you put something you don't understand something else you may not understand either. For example:

for (var i = 1; i <= 4; i++) {
   setTimeout(function() { console.log(i); }, 1000*i); // 5 5 5 5 
}

Weird right?&...