What is the difference between document.write(‘hello world\n’);
and document.writeln(‘hello world’);
?
Edit
My question is what will be the difference of output.
The Difference Between write() and writeln() writeln() adds a newline character after each statement. write() does not.
write and writeln are the same function. The only difference is that writeln adds a new line at the end of the text.
Historically, writeln
was intended to handle different newline conventions, of with \n
is only one.
There are different conventions for end-of-line. '\n'
is the end-of-line marker on UNIX, '\r'
on Mac (AFAIK not any more as it's now a UNIX) and '\r\n'
is DOS/Windows. Using writeln
should automatically use the correct one on the desired platform in other languages, but I don't really know whether JavaScript's document.writeln
automatically uses the correct one automagically.
The writeln() method is identical to the write() method, with the addition of writing a newline character after each statement.
from w3schools.com
edit: for the sake of completeness :)
writeln on mozilla.org
writeln on w3.org
In theory, writeln() appends a line feed to the end of your string.
In practice, since you're talking Javascript, there's little real difference if you're generating HTML, since HTML ignores extra white space anyway.
afaik there's no difference between them. You'll end up with a line, which has a "new-line-sign" at the end, so the next text youre gonna display will show up in the following line.
if this is a tricky question sorry for my ignorance:)
document.write() writes to the document without appending a newline on the end. document.writeln() writes to the document appending a newline at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With