So far this tutorial has relied on just two methods of output; console.log
and console.error
. JavaScript provides at least four methods of output. This part of the tutorial will describe two additional methods of output.
document.write
The function used thus far have all been highly unobtrusive and do not do anything but allow debugging. The document.write
is another very useful debugging output method.
document.write("Hello world!")
Another form of this is the is document.writeln
which will write a line to the document:
document.writeln("Hello world!")
Using the document.write
and the document.writeln
functions will overwrite any existing HTML in the document. and should only be used for debugging purposes.
window.alert
The most useful output when developing a usable web document that JavaScript provides is the window.alert
function.
window.alert("Hello world!")
The window.alert
function is a formalised version of the alert
function:
alert("Hello world!")