The above command will print Hello World in the web browser. Full code is here
<script>
document.write('Hello World');
</script>
We can use document object to send output to the client browser from our JavaScript code block. This is a simple way to send output and we can print any text we want to write. We can print the output within our JavaScript code block only.
We can add line break before this by using document.writeln. We can also add a line break like above example where ever required.
document.write(my_var + "<br>"+my_var1 )
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.