Running the following script in javascript or nodejs or any other javascript environment prints:
undefined
0
1
2
3
4
Script:
for(var i=0;i<5;i++){
var a = function (i) {
setTimeout(function () {
console.log(i);
},i*1000);
};
a(i);
}
Where does the undefined
comes from?