“document.write(‘hello world\n’);” and “document.writeln(‘hello world’);” what is the difference between both?
edit
My question is what will be the difference of output.
“document.write(‘hello world\n’);” and “document.writeln(‘hello world’);” what is the difference between both?
edit
My question is what will be the difference of output.
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:)
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 :)
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.
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.
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.