for (var a=0; a<5; a++)
{
setTimeout(function(){
alert(a);
}, 0);
}
The above code in javascript is prompting me with the output of 5, 5 times infact my expectation was of the output something like 0,1,2,3,4 but rather it shows me the output of 5,5,5,5,5. Why is it so?
Besides that please explain me the concept of context and scope in javascript i always fail to understand it through many examples reading from the web.