In this section we will learn what the document writeln() method is and how to use it in JavaScript.
What is document writeln() Method in JavaScript?
The JavaScript document writeln() method is used to write content (including source codes) to output stream.
This output stream is basically the page that users see!
This means if there’s already a document displayed to users, then calling this method on top of the document will remove the old content and display the new content instead.
For example, using this method we can send a message like “Hello World” to the page.
Or put HTML elements as the argument of this method and they will be rendered on the page.
Note: this method works the same as the write() method with the exception that the writeln() method adds a newline character per each call to the method.
For example, if you call the writeln() method three times, then you’ll get three new lines as a result of calling this method.
document writeln() Method Syntax:
document.writeln(arg1,arg2,arg3,…,argn)
document writeln() Method Parameters
The function takes one or more arguments and it will combine and send them to the output stream.
document writeln() Method Return Value
The method does not return a value.
Example: using document writeln() Method in JavaScript
See the Pen using document writeln() Method in JavaScript by Omid Dehghan (@odchan1) on CodePen.