Print new line in javascript

In JavaScript, you can print a new line using the following methods:

  1. Using the \n character:

    console.log("Hello");
    console.log("\nWorld");

    This will print "Hello" followed by a new line, and then "World".

  2. Using the document.write() method:

    document.write("Hello");
    document.write("<br>");
    document.write("World");

    This will print "Hello" followed by a <br> tag, which represents a new line, and then "World".

  3. Using the innerHTML property:

    var paragraph = document.createElement("p");
    paragraph.innerHTML = "Hello";
    document.body.appendChild(paragraph);
    paragraph.innerHTML += "<br>";
    paragraph.innerHTML += "World";

    This will create a new paragraph element, set its inner HTML to "Hello", append it to the document body, and then append a new line and "World" to the paragraph.

  4. Using the console.log() method with a newline character:

    console.log("Hello");
    console.log("World");

    This will print "Hello" and "World" on separate lines in the console.

Note that the \n character is not recognized by all browsers, so it's generally recommended to use the document.write() or innerHTML methods for printing new lines in a web page.