Exciting things

Puzzle with Javascript loop on iOS Safari and UIWebView

After doing a small test with Javascript looping on iOS UIWebView control and the iOS Safari, I put a puzzle to our developers. It’s funny but is a very important thing you need to know when developing Javascript on these “platforms” 🙂

What is the final “i” value output of the script below:

var i = 0;
for (i=0; i<500; i++) {
      document.write(i);
}

Answers for iOS Safari:

  • less than 50
  • 499
  • less than 100

Answers for iOS UIWebview:

  • less than 50
  • 499
  • less than 100

Don’t scroll down – answer yourself firstly. You will find the answer in the bottom of this article

.

.

.

.

.

On iOS UIWebView, the loop will go to the end (499). On the Safari (iOS), the loop will be terminated less than 50 (I don’t remember exactly the value, but it cannot exceed 50 loop times).

And now, another puzzle with the same code as above for iOS UIWebView – but the loop will increase to 1.000.000 times?

What is your answer? 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *