2.0 KiB
2.0 KiB
id, challengeType, videoUrl, forumTopicId, title
id | challengeType | videoUrl | forumTopicId | title |
---|---|---|---|---|
56533eb9ac21ba0edf2244d3 | 1 | https://scrimba.com/c/cKekkUy | 16791 | 严格不等运算符 |
Description
!==
)与全等运算符是相反的。这意味着严格不相等并返回false
的地方,用严格相等运算符会返回true
,反之亦然。严格不相等运算符不会转换值的数据类型。
示例
3 !== 3 // false
3 !== '3' // true
4 !== 3 // true
Instructions
if
语句中,添加严格不相等运算符!==
,这样如果val
与17
严格不相等的时候,函数会返回 "Not Equal"。
Tests
tests:
- text: <code>testStrictNotEqual(17)</code>应该返回 "Equal"。
testString: assert(testStrictNotEqual(17) === "Equal");
- text: <code>testStrictNotEqual("17")</code>应该返回 "Not Equal"。
testString: assert(testStrictNotEqual("17") === "Not Equal");
- text: <code>testStrictNotEqual(12)</code>应该返回 "Not Equal"。
testString: assert(testStrictNotEqual(12) === "Not Equal");
- text: <code>testStrictNotEqual("bob")</code>应该返回 "Not Equal"。
testString: assert(testStrictNotEqual("bob") === "Not Equal");
- text: 应该使用 <code>!==</code> 运算符。
testString: assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
Challenge Seed
// Setup
function testStrictNotEqual(val) {
if (val) { // Change this line
return "Not Equal";
}
return "Equal";
}
// Change this value to test
testStrictNotEqual(10);
Solution
function testStrictNotEqual(val) {
if (val !== 17) {
return "Not Equal";
}
return "Equal";
}