How is "\n" supposed to look? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is "\n" supposed to look?

I tried "\n" and "\t" and I didn't notice a single difference other than the favt that it didn't have apostophies

27th Jan 2017, 4:27 PM
toney
toney - avatar
3 Answers
+ 4
"\t" is tab ya know but with "document.write" doesnt show result as well You should use at "alert" function
27th Jan 2017, 4:34 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
They move the cursor; the next place something text-related is going to happen (keypresses, printing, scrolling). Try putting \n and \t inside text (not just by themselves) and see what happens.
27th Jan 2017, 5:06 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Outputing JS is done in Html, so all spaces characters ( including tabs and new lines ) are handled as only one space when several nexted... This is the default behaviour of Html formatting. If you want to keep spaces and new lines as is, you must play with the css 'white-space' property ( or use the <pre> 'pre-formatted' tag which have already the default behaviour to keep spaces and new lines ) Anyway, on an alert() output, we don't be in Html format, so the default behaviour is to print all spaces and new lines ^^
28th Jan 2017, 1:33 AM
visph
visph - avatar