1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244d1 | 严格相等运算符 | 1 | https://scrimba.com/c/cy87atr | 16790 | comparison-with-the-strict-equality-operator |
--description--
严格相等运算符(===)是相对相等操作符(==)的另一种比较操作符。 与相等操作符转换数据两类型不同,严格相等运算符不会做类型转换。
如果比较的值类型不同,那么在严格相等运算符比较下它们是不相等的,会返回 false 。
示例
3 === 3
3 === '3'
这些条件将分别返回 true and false。
在第二个例子中,3 是一个 Number 类型,而 '3' 是一个 String 类型。
--instructions--
在 if 语句中,添加严格相等运算符,这样函数在当 val 严格等于 7 的时候,会返回 Equal。
--hints--
testStrict(10) 应该返回字符串 Not Equal
assert(testStrict(10) === 'Not Equal');
testStrict(7) 应该返回字符串 Equal
assert(testStrict(7) === 'Equal');
testStrict("7") 应该返回字符串 Not Equal
assert(testStrict('7') === 'Not Equal');
你应该使用 === 运算符。
assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
--seed--
--seed-contents--
// Setup
function testStrict(val) {
if (val) { // Change this line
return "Equal";
}
return "Not Equal";
}
testStrict(10);
--solutions--
function testStrict(val) {
if (val === 7) {
return "Equal";
}
return "Not Equal";
}