Skip to content Skip to sidebar Skip to footer

Which Browsers Support Multi-line Strings?

Which browsers support multi-line strings? 'foo \ bar' As usual, my main suspect for not supporting it is IE. Which IE version is the first that supports it?

Solution 1:

All current versions of the major browsers accept multi-line strings.

Note: this technique is apparently not in compliance with browser standards; however, it works out fine when tested across all current versions of the major browsers.

  • Some online tools such as JSLint don't allow it
  • Multi-line strings can be dangerous in JavaScript because all hell breaks loose if you accidentally put a whitespace in between the escape character (\) and a new line. (@ripper234 comment)

Multiline String literals are disallowed by the Google Style Guide.

Solution 2:

The accent grave (back-quote, back tick) character works like a quotation mark to define multiline strings in Javascript in Firefox and Google chrome, but not in Internet Explorer 11. These strings are called Template Literals and are part of the ES6 specification. I'm guessing that the generated newline sequence is what your editor generates, not what is expected on the computer that is interpreting the Javascript code.

Example:

var str=`This string
has three
lines.`;

Post a Comment for "Which Browsers Support Multi-line Strings?"