As per my understanding, the below function should print 5 five times because of hoisting. But instead, it prints 6 five times.
Question is, how come it prints 6 when the loop's limit is <=5?
function () {
for ( var i = 1; i <= 5; i++) {
setTimeout( function() {
console.log(i); // this should print '5' five times
}, i * 1000)
}
}