--- id: 56533eb9ac21ba0edf2244d1 title: Comparison with the Strict Equality Operator challengeType: 1 videoUrl: 'https://scrimba.com/c/cy87atr' forumTopicId: 16790 localeTitle: 严格相等运算符 --- ## Description
严格相等运算符(===)是相对相等操作符(==)的另一种比较操作符。与相等操作符不同的是,它会同时比较元素的值和数据类型。 如果比较的值类型不同,那么在严格相等运算符比较下它们是不相等的,会返回 false 。 示例 ```js 3 === 3 // true 3 === '3' // false ``` 3是一个数字类型的,而'3'是一个字符串类型的,所以 3 不全等于 '3'。
## Instructions
if语句值使用严格相等运算符,这样当val严格等于7的时候,函数会返回"Equal"。
## Tests
```yml tests: - text: testStrict(10)应该返回 "Not Equal"。 testString: assert(testStrict(10) === "Not Equal"); - text: testStrict(7)应该返回 "Equal"。 testString: assert(testStrict(7) === "Equal"); - text: testStrict("7")应该返回 "Not Equal"。 testString: assert(testStrict("7") === "Not Equal"); - text: 你应该使用===运算符。 testString: assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0); ```
## Challenge Seed
```js // Setup function testStrict(val) { if (val) { // Change this line return "Equal"; } return "Not Equal"; } // Change this value to test testStrict(10); ```
## Solution
```js function testStrict(val) { if (val === 7) { return "Equal"; } return "Not Equal"; } ```