The above command will print Hello World in the web browser. Full code is here
We can print variables like this.
We can print two variables like this
Adding Line BreakWe can add line break before this by using document.writeln. We can also add a line break like above example where ever required.
Using document.writeln()document.writeln() will add one line break after the statement. However while displaying, HTML will remove all white space and keep one single space, so new line will not be displayed. To get line break we will keep our code inside <pre> tag.
Exercise Keep the document.write() inside a function. Trigger the function on button click to show the message Hello World
Subscribe to our YouTube Channel here
This article is written by plus2net.com team.