How to new line string - JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Use <br> tag for a new line.


Following is the code −

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
   <h1 id="headingDemo">
      My Name is David Miller
   document.getElementById("headingDemo").innerHTML = "My Favourite Subject is JavaScript" + '<br>' + "I live in AUS.";

To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.

The output is as follows −

Updated on 03-Oct-2020 13:49:53