String
类型的值使用+
操作符的时候,它被称作 拼接操作符。你可以通过拼接其他字符串来创建一个新的字符串。
示例
```js
'My name is Alan,' + ' I concatenate.'
```
提示+
操作符,把字符串"This is the start. "
和"This is the end."
连接起来并赋值给变量myStr
。
myStr
的值应该是This is the start. This is the end.
。
testString: assert(myStr === "This is the start. This is the end.");
- text: 使用+
操作符构建myStr
。
testString: assert(code.match(/(["']).*(["'])\s*\+\s*(["']).*(["'])/g).length > 1);
- text: myStr
应该被var
关键字声明。
testString: assert(/var\s+myStr/.test(code));
- text: 确保有给myStr
赋值。
testString: assert(/myStr\s*=/.test(code));
```