new line with javascript write
How to create a new line with JavaScript?
If you want to create a new line with JavaScript, you can use the escape
character followed by the character code for a new line. The code for a new line is \n
.
Example:
let message = "Hello!\nHow are you doing today?";
console.log(message);
This code will output:
Hello!
How are you doing today?
Another way to create a new line is to use the template literals
syntax. You can use backticks (`
) to enclose a string that can contain placeholders for variables.
Example:
let name = "Raju";
let message = `Hello ${name}!How are you doing today?`;
document.getElementById("myDiv").innerHTML = message;
This code will add the message to an HTML div:
And the output will be:
Hello Raju!
How are you doing today?