Hi I am new to javascript and having trouble with it. It only works when I use window.onload. If i try to write a script and use document.write("blahblah"); the document shows up blank. What could be the issue here?

p.s. someone else recommended that i try using window.onload function() {document.write("blahblah")}
and it worked but i can't write scripts normally without it.
can someone please explain why?