How to Create a New Line in an Alert Box Using JavaScript?

Estimated read time 1 min read

In JavaScript, you can create a new line in an alert box by using the special character sequence \n. The \n sequence represents a line break and is equivalent to pressing the Enter key on your keyboard.

Here’s an example of how to create a new line in an alert box:

alert("Line 1\nLine 2\nLine 3");

In this example, the alert function is passed a string that contains three lines separated by the \n character sequence. When the alert box is displayed, the string will be displayed on three separate lines.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply