2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244d1
2021-02-06 04:42:36 +00:00
title: Comparison with the Strict Equality Operator
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cy87atr'
forumTopicId: 16790
2021-01-13 03:31:00 +01:00
dashedName: comparison-with-the-strict-equality-operator
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
Strict equality (`===` ) is the counterpart to the equality operator (`==` ). However, unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
If the values being compared have different types, they are considered unequal, and the strict equality operator will return false.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
**Examples**
2020-04-29 18:29:13 +08:00
```js
3 === 3 // true
3 === '3' // false
```
2021-02-06 04:42:36 +00:00
In the second example, `3` is a `Number` type and `'3'` is a `String` type.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Use the strict equality operator in the `if` statement so the function will return "Equal" when `val` is strictly equal to `7`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testStrict(10)` should return "Not Equal"
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(testStrict(10) === 'Not Equal');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`testStrict(7)` should return "Equal"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testStrict(7) === 'Equal');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testStrict("7")` should return "Not Equal"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testStrict('7') === 'Not Equal');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should use the `===` operator
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
// Setup
function testStrict(val) {
if (val) { // Change this line
return "Equal";
}
return "Not Equal";
}
testStrict(10);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function testStrict(val) {
if (val === 7) {
return "Equal";
}
return "Not Equal";
}
```