line break in javascript

To create a line break in Javascript, you can use the escape character \n. This will insert a newline character and move the text to the next line.

Example:

index.tsx
console.log("Hello\nWorld");
29 chars
2 lines

Output:

index.tsx
Hello
World
12 chars
3 lines

You can also use the <br> tag in combination with Javascript to add a line break in HTML.

Example:

index.tsx
document.getElementById("myText").innerHTML = "Hello<br>World";
64 chars
2 lines

Output:

index.tsx
Hello
World
12 chars
3 lines

gistlibby LogSnag