Javascript can be used to display data on the front end and on the server. So, there are two ways to add a line break:
-
Frontend
-
Server
Frontend
<html>
<head>
<title>Hello World</title>
</head>
<body>
<script>
document.write("hello")
document.write("<br />")
document.write("world")
</script>
</body>
</html>
Server
To log data on the server, we must use console.log()
. To line break inside the console.log() we can’t use the <br />
inside it. Therefore, here comes a \n
which breaks the line inside the console:
let greet = "hello\nworld"
console.log(n)
Thanks for reading
Follow me on Twitter
Thanks for reading!