--- id: 56533eb9ac21ba0edf2244b5 title: Escaping Literal Quotes in Strings challengeType: 1 videoUrl: '' localeTitle: 逃避字符串中的字面引用 --- ## 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
```yml tests: - text: 您应该使用两个双引号( " )和四个转义双引号( \" )。 testString: 'assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2, "You should use two double quotes (") and four escaped double quotes (\").");' - text: 变量myStr应该包含字符串: I am a "double quoted" string inside "double quotes". testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".", "Variable myStr should contain the string: I am a "double quoted" string inside "double quotes".");' ```
## Challenge Seed
```js var myStr = ""; // Change this line ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```