Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
To add a new line into a JavaScript string can I use the following code?
Is it according to programming standards? Is there another way to do this?
For example,
var string = "check"; alert(string); var newstring = string + "\n\n"; alert(newstring);
I think it is fine. If you are using alert for the debugging purposes, Please use console.log("string + "\n"); instead.
console.log("string + "\n");
Add a comment
\n
is the right way to handle new lines in alert boxes.
Simply add a \n everytime you want a new line in your string :
var str = 'Test\nTest2\nTest3'; alert(str);
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.