+ 2
How to add a newline in JS?
My code: var num = 10; document.write(num == 8,"\n"); document.write(num === "10"); Why \n is not adding a new line?
5 Answers
+ 6
Because you're using document.write it means you output HTML code. You have to use <br/> here as <br/> is a line break in HTML. If you were using console.log, "\n" would work.
+ 11
Use <br> instead of \n
+ 4
Bartikaš¶ why?
As said in JS course in sololearn, \n means newline! https://www.sololearn.com/learning/1129/
+ 4
Faheem
You are correct but pls note that document.write() function renders the whole thing in html... so you need to use html tags
+ 2
A new line is added but HTML strips newlines and other forms of whitespace. Remember?
The right way to include a line break is using <br> or enclosing in a block element.