Table of Contents
The document property returns the document object of the window which is being used. When an HTML element is loaded onto the web browser then it becomes a part of the document object. The document object (in the window object) is the root node of the HTML page. One can access the document object either by using window.document or just document. Here is how one can access it:
How does document.write work?
document.write(arg1, arg2, arg3, …)
Writing some text directly on an HTML document
Writing some text and HTML elements on an HTML document
Remember that document.write() when used multiple times will give the output on the same line.
document.write(“This is line 1”); document.write(“This is line 2”); // output: This is line 1This is line 2
If you want to print on a new line, then you can make use of the writeln() method. It is similar to document.write() but the only difference is that the output will be displayed on a new line. For example,
document.writeln(“This is line 1”); document.writeln(“This is line 2”); /* output: This is line 1 This is line 2 */
Although there is no use of writeln() in HTML as if you want to go to the next line you can make use of <br>
If you want to practice these code snippets then go ahead and check Codedamn’s playground. This is an online compiler where you can play around with your code and understand coding concepts all inside a browser.
Learn programming on codedamn
Codedamn is an interactive coding platform with tons of sweet programming courses that can help you land your first coding job. Here's how:
- Step 1 - Create a free account
- Step 2 - Browse the structured roadmaps (learning paths), or see all courses.
- Step 3 - Practice coding for free on codedamn playgrounds.
- Step 4 - Upgrade to a Pro membership account to unlock all courses and platforms.
Programming is one of the most in-demand jobs today. Learning to program can change your future. All the best!
Sharing is caring
Did you like what Vishnupriya wrote? Thank them for their work by sharing it on social media.