最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Which browsers support multi-line strings? - Stack Overflow

programmeradmin5浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 13

All 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.`;
发布评论

评论列表(0)

  1. 暂无评论