-4

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);
0

3 Answers 3

0

I think it is fine. If you are using alert for the debugging purposes, Please use console.log("string + "\n"); instead.

Sign up to request clarification or add additional context in comments.

Comments

0
\n 

is the right way to handle new lines in alert boxes.

Comments

0

Simply add a \n everytime you want a new line in your string :

var str = 'Test\nTest2\nTest3';
alert(str);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.