Can someone explain to me why undefined is being printed only in firefox for document.write on the last line. When the first document.write is removed however it works great, and it seems to be like this only in Firefox.
document.write("Hello <br />");
myVar = 55;
document.write(window.myVar);
It’s because of jsfiddle. You have the script wrapped in an anonymous function that’s bound to the page’s onload event with mootools’s
addEvent()function. For some reason running the code in an onload event causes the scope not bewindowin Firefox.If you look at the page source the code looks like this:
If you run the same script without any libraries and not in any event it works fine: http://jsfiddle.net/43pbj/4/