2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 56533eb9ac21ba0edf2244d3
|
|
|
|
|
challengeType: 1
|
2020-04-29 18:29:13 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/cKekkUy'
|
|
|
|
|
forumTopicId: 16791
|
2020-10-01 17:54:21 +02:00
|
|
|
|
title: 严格不等运算符
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-04-29 18:29:13 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
严格不相等运算符(<code>!==</code>)与全等运算符是相反的。这意味着严格不相等并返回<code>false</code>的地方,用严格相等运算符会返回<code>true</code>,<em>反之亦然</em>。严格不相等运算符不会转换值的数据类型。
|
|
|
|
|
<strong>示例</strong>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
3 !== 3 // false
|
|
|
|
|
3 !== '3' // true
|
|
|
|
|
4 !== 3 // true
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-04-29 18:29:13 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
在<code>if</code>语句中,添加严格不相等运算符<code>!==</code>,这样如果<code>val</code>与<code>17</code>严格不相等的时候,函数会返回 "Not Equal"。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>testStrictNotEqual(17)</code>应该返回 "Equal"。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(testStrictNotEqual(17) === "Equal");
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>testStrictNotEqual("17")</code>应该返回 "Not Equal"。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(testStrictNotEqual("17") === "Not Equal");
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>testStrictNotEqual(12)</code>应该返回 "Not Equal"。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(testStrictNotEqual(12) === "Not Equal");
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: <code>testStrictNotEqual("bob")</code>应该返回 "Not Equal"。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(testStrictNotEqual("bob") === "Not Equal");
|
2020-04-29 18:29:13 +08:00
|
|
|
|
- text: 应该使用 <code>!==</code> 运算符。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// Setup
|
|
|
|
|
function testStrictNotEqual(val) {
|
2020-04-29 18:29:13 +08:00
|
|
|
|
if (val) { // Change this line
|
2018-10-10 18:03:03 -04:00
|
|
|
|
return "Not Equal";
|
|
|
|
|
}
|
|
|
|
|
return "Equal";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change this value to test
|
|
|
|
|
testStrictNotEqual(10);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2020-04-29 18:29:13 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```js
|
2020-04-29 18:29:13 +08:00
|
|
|
|
function testStrictNotEqual(val) {
|
|
|
|
|
if (val !== 17) {
|
|
|
|
|
return "Not Equal";
|
|
|
|
|
}
|
|
|
|
|
return "Equal";
|
|
|
|
|
}
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|