0
var z = `line
next line`;

alert(z);
/* OUTPUT
line
next line
*/

document.getElementById("demo").innerHTML = z;
/* OUTPUT
line next line
*/

I am using Firefox. Am I missing something here? Or is this supposed to work this way? I have referred to the Multiline String section of the mozilla developer org website (Sorry, I was unable to post more than 2 links here !!)

Screenshot for output in innerHTML

Screenshot for output in alert

  • what about `var z = 'line' +
    + 'next line';`
    – Sergio Alen Oct 05 '17 at 23:38
  • `
    ` tag is not present in your link...
    – La masse Oct 05 '17 at 23:42
  • 1
    HTML parsers don't process the newline, `\n`, character the same way plain text viewers do. You need an element that is styled to break after it's content. – AJ X. Oct 05 '17 at 23:42
  • @Lamasse The OP had the `
    ` tags inserted because they didn't know how to put a code block in their question. I forgot to remove it, sorry.
    – 4castle Oct 05 '17 at 23:45
  • Please include all info *within the body of the question*. Links may be unavailable, which could render the question useless. Also, it's easier for users to help if they don't have to jump around the web to gather pertinent info. Thanks, All the Best. – SherylHohman Oct 05 '17 at 23:52
  • They "work" the same as normal pre-ES6 multiline strings; that is to say, newlines will surface in any context that does not collapse white space, which include the 2 you have pointed out, as well as text in a `
    ` or `whitespace:pre` block, or in a `
    – chiliNUT Oct 05 '17 at 23:52
  • @SergioAlen Thank you for replying. I am aware of the traditional concatenation and
    usage. I was curious to know how to use the multiline feature of ES6
    – Nehal Bhanushali Oct 06 '17 at 00:19
  • Thanks @axlj ! So I must wrap them in elements that displays text as it is like
     to be able to use multiline in div display.
    – Nehal Bhanushali Oct 13 '17 at 21:39

0 Answers0