Unexpected JavaScript infinite loop when checking for body tag -


i going asap script checks if body tag loaded, causes whole page freeze.

here is:

while (!document.body)     if (document.body) console.log('loaded'); 

this of course wouldn't work in cases, i'm puzzled why becomes infinite loop , freezes page.

javascript single-threaded. while loop running, nothing else runs, body can't loaded. there's nothing in body of loop changes value of document.body, if it's not set when start, never be.


Comments