why doesn't "\n" work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why doesn't "\n" work?

var i=20; do { document.write(i); document.write("\n") document.write("<br/>"); i++; } while (i<=25); //doesn't JS support "\n"?

27th Dec 2021, 5:31 PM
Harsha S
Harsha S - avatar
5 Answers
+ 2
No, it's HTML who doesn't support it : document.write adds to the HTML page the string passed as its parameters and HTML doesn't support break lines with \n but with <br /> and \n won't render because JS will first evaluate the unicode then will render a simple new line
27th Dec 2021, 5:48 PM
VCoder
VCoder - avatar
+ 2
thanks VCoder
27th Dec 2021, 5:52 PM
Harsha S
Harsha S - avatar
+ 1
To prove that JS support \n, try : console.log("Hello\nWorld");
27th Dec 2021, 5:50 PM
VCoder
VCoder - avatar
+ 1
You're welcome, if you follow me, I will be able to help you in the DOM and introduce you in : "Creating your own tags and attributes" topic
27th Dec 2021, 5:55 PM
VCoder
VCoder - avatar
0
VCoder sure!
27th Dec 2021, 6:14 PM
Harsha S
Harsha S - avatar