To add to what JMRKER said, whitespace is handled automatically if it's in the body of your page, but not when used in alert boxes and input elements etc. So all your whitespace characters (spaces, new lines etc.) are treated like a single space until the text needs to wrap to the next line, in which case the whitespace character (whatever it is) is treated like a newline character.
Another example that would show this would be writing several spaces after each other:
alert("Hello foo bar."); // shows several spaces between foo and bar
document.write("Hello foo bar."); // shows only a single space