Saturday 8 December 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...