Why writeln (); without creating a new line?

  <script type='text/javascript'> 
  //<![CDATA[
   for(var j = 0; j < 6;) {
    document.writeln(++j);
   }
  //]]>
  </script>

in the above code, suppose you need to give a new line if you turn to the definition The writeln() method is identical to the write() method, with the addition of writing a newline character after each statement.

But in my case, the conclusion 123456

UPDATE:

I will find a better answer, but with all the answers are correct, and I believe that next time someone will have the same question, so I thought I should just update the answer to the top and remove the homework tag so that it benefits everyone .

The reason why a new line is not created is because, because it actually creates '\ n'

"\ n" in the browser, if I'm not mistaken, this does not affect the display on the screen, but if you look at the source code of the page, you will see that my output will display something like this

1
2
3
4
5
6

, , <br\>, break-line, , .

  <script type='text/javascript'> 
  //<![CDATA[
   for(var j = 0; j < 6;) {
    document.writeln(++j);
    document.writeln("<br>");
   }
  //]]>
  </script>
+3
7

, . , , .

, " " HTML .

, , - HTML-, .

  <script type='text/javascript'> 
  //<![CDATA[
   for(var j = 0; j < 6;) {
    document.write(++j);
    document.writeln("<br>");
   }
  //]]>
  </script>

PRE (aka preformatted) (. W3 PRE ), .

+2

, HTML

<p>
1
2
3
4
</p>

.

+5

'\n' .

CSS <pre> ; <br/> ( ) (<div>, <p> ..), .

+5

\n <pre></pre>. HTML, <br />, .

+2

, , . :

var i = 0;
document.write('<pre>');
while ( i < 5 ) document.writeln(++i); 
document.write('</pre>');

- , .

+1

<br/>. W3Schools .

+1

snoop Firebug Noteapd ++, , . , HTML .

+1

All Articles