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?
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?
Share Improve this question edited May 23, 2017 at 11:45 CommunityBot 11 silver badge asked Dec 10, 2012 at 19:47 ripper234ripper234 230k280 gold badges645 silver badges914 bronze badges 3- 7 What browsers don't support it? – PeeHaa Commented Dec 10, 2012 at 19:48
- 2 According to the last ment on the post you linked to, this capability is defined in ECMA-262 5th Edition. From there I guess wikipedia is a good reference - en.wikipedia/wiki/ECMAScript#Dialects. – Lix Commented Dec 10, 2012 at 19:54
- Specifically, when did IE start supporting it? Do IE 7/8 support it? – ripper234 Commented Dec 11, 2012 at 9:19
2 Answers
Reset to default 13All current versions of the major browsers accept multi-line strings.
Note: this technique is apparently not in pliance 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 ment)
Multiline String literals are disallowed by the Google Style Guide.
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 puter that is interpreting the Javascript code.
Example:
var str=`This string
has three
lines.`;