I figure that both \ and \n can be used as a line break. What is the difference?
EDIT: Sorry I realized that I was wrong. The tutorial was talking about / as a line break for the programmer, which wasn’t displayed, i.e:
alert("Hi \
there");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
\nis the only correct escape code for a newline (short of using things like\u000aor similar).Note that the below code does not actually insert line breaks (would still need the actual
\nescape code):The result is ‘qwertyuiopasdfghjklqwertyuiopasdfghjklqwertyuiopasdfghjkl’. I also don’t recommend the above code because indenting the continuation lines causes problems with unwanted spaces in your string. One good alternative, though, is: