JavaScript > Strings

Line breaking strings in JavaScript

How to line break long string lines in JavaScript?


For breaking the long code lines we can follow the below code.

    <div id="myId"></div>
    
    <script>
        var a = "The Most popular website for learning the technology is:"
        document.getElementById("myId").innerHTML = a + "<br/>"+ "TechFunda.Com";
    </script>

    <br />

    <div id="Div"></div>
    
    <script>
        var c = "The Most popular website for learning the technology is:";
        document.getElementById("Div").innerHTML = c + "<br/>" + "TechFunda" + ".Com";
    </script>

In the above code snippet we break the same code in two ways, in first type we use the normal method, in the second type we break the code with plus operator ("TechFunda" + ".Com"). Both ways gives the same result, but the perfect way to break the code lines is after the operator or comma, and the safest way to break the code lines is with the help of "+" operator. 

OUTPUT

 Views: 692 | Post Order: 64



Write for us