Saturday, December 8, 2018

Weird value for counter variable in javascript

Your for loop is being executed at page load time. The alert only fires when there's a click event which is happening after the for loop has finished. Hence the value of i is now 6.


1) Page loads, for loop does its stuff...


2) Sometime later a click event is fired. the value of i at this time is 6 because the forloop has already completed.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...