--- id: 56533eb9ac21ba0edf2244b6 title: Escape Sequences in Strings challengeType: 1 videoUrl: '' localeTitle: 字符串中的转义序列 --- ## Description
引号不是可以在字符串中转义的唯一字符。使用转义字符有两个原因:首先是允许您使用您可能无法输入的字符,例如退格。其次是允许你在一个字符串中表示多个引号,而不会误解你的意思。我们在之前的挑战中学到了这一点。
产量
\' 单引号
\" 双引号
\\ 反斜线
\n 新队
\r 回车
\t 标签
\b 退格
\f 形式饲料
请注意,必须对反斜杠本身进行转义才能显示为反斜杠。
## Instructions
使用转义序列将以下三行文本分配到单个变量myStr
第一行
\第二行
ThirdLine
您将需要使用转义序列正确插入特殊字符。您还需要按照上面的间距来跟踪,在转义序列或单词之间没有空格。这是写出转义序列的文本。 FirstLine newline tab backslash SecondLine newline ThirdLine
## Tests
```yml tests: - text: myStr不应包含任何空格 testString: 'assert(!/ /.test(myStr), "myStr should not contain any spaces");' - text: myStr应包含的字符串FirstLineSecondLineThirdLine (记住区分大小写) testString: 'assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr), "myStr should contain the strings FirstLine, SecondLine and ThirdLine (remember case sensitivity)");' - text: FirstLine后面应跟换行符\n testString: 'assert(/FirstLine\n/.test(myStr), "FirstLine should be followed by the newline character \n");' - text: myStr应该包含一个制表字符\t ,它跟在换行符后面 testString: 'assert(/\n\t/.test(myStr), "myStr should contain a tab character \t which follows a newline character");' - text: SecondLine应该以反斜杠字符\\开头 testString: 'assert(/\SecondLine/.test(myStr), "SecondLine should be preceded by the backslash character \\");' - text: SecondLineThirdLine之间应该有换行符 testString: 'assert(/SecondLine\nThirdLine/.test(myStr), "There should be a newline character between SecondLine and ThirdLine");' ```
## Challenge Seed
```js var myStr; // Change this line ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```