What is the difference between write and writeln in JavaScript
Last updated:4th Nov 2021
document.writeln()
is the same as document.write()
but only it adds a newline character after each statement. for example
keep Writeln() inside pre tag
<html>
<body>
<p>Write() method not add new line after each stetement</p>
<script>
document.write("Hello Word!1");
document.write("Hello Word!2");
</script>
<p>Writeln() add new line after each stetement.</p>
<pre><script>
document.writeln("Hello everyone1");
document.writeln("Hello everyone2");
</script>
</pre>
</body>
</html>
output
Write() method not add new line after each stetement Hello Word!1Hello Word!2 Writeln() add new line after each stetement. Hello everyone1 Hello everyone2