2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244b5 | Escaping Literal Quotes in Strings | 1 | 逃避字符串中的字面引用 |
Description
"
还是'
?你的字符串里面在JavaScript中,你可以放置一个反斜杠 (从考虑到它作为字符串报价的最终逃脱报价\
在引号前)。 var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
这告诉JavaScript,以下引用不是字符串的结尾,而是应该出现在字符串中。所以如果要将它打印到控制台,你会得到: Alan said, "Peter is learning JavaScript".
Instructions
myStr
变量,这样如果要将其打印到控制台,您会看到: I am a "double quoted" string inside "double quotes".
Tests
tests:
- text: 您应该使用两个双引号( <code>"</code> )和四个转义双引号( <code>\"</code> )。
testString: 'assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2, "You should use two double quotes (<code>"</code>) and four escaped double quotes (<code>\"</code>).");'
- text: 变量myStr应该包含字符串: <code>I am a "double quoted" string inside "double quotes".</code>
testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".", "Variable myStr should contain the string: <code>I am a "double quoted" string inside "double quotes".</code>");'
Challenge Seed
var myStr = ""; // Change this line
After Test
console.info('after the test');
Solution
// solution required