function x(){
    for(var i=1; i<=5; i++){
        setTimeout(
            function(){
                console.log(i);
            },
            i * 1000
        );
    }
}
x();
so I was Expecting That the output would be 5 5 5 5 5 as because of setTimeout the loop will complete its cycle and because of that closure will have that i=5 as the condition is i<=5 but the output is 6 6 6 6 6 and I just want to clear it up that how it broke the loop and went to 6?
 
    