2018-09-30 22:01:58 +00:00
---
id: 56533eb9ac21ba0edf2244d1
title: Comparison with the Strict Equality Operator
challengeType: 1
2019-02-14 17:24:02 +00:00
videoUrl: 'https://scrimba.com/c/cy87atr'
2019-07-31 18:32:23 +00:00
forumTopicId: 16790
2021-01-13 02:31:00 +00:00
dashedName: comparison-with-the-strict-equality-operator
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
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.
2018-09-30 22:01:58 +00:00
If the values being compared have different types, they are considered unequal, and the strict equality operator will return false.
2020-11-27 18:02:05 +00:00
**Examples**
2019-05-17 13:20:30 +00:00
```js
2022-02-23 17:58:42 +00:00
3 === 3 // true
3 === '3' // false
2019-05-17 13:20:30 +00:00
```
2020-11-27 18:02:05 +00:00
In the second example, `3` is a `Number` type and `'3'` is a `String` type.
# --instructions--
2021-10-25 16:55:58 +00:00
Use the strict equality operator in the `if` statement so the function will return the string `Equal` when `val` is strictly equal to `7` .
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-03-03 00:12:12 +00:00
`testStrict(10)` should return the string `Not Equal`
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(testStrict(10) === 'Not Equal');
```
2021-03-03 00:12:12 +00:00
`testStrict(7)` should return the string `Equal`
2020-11-27 18:02:05 +00:00
```js
assert(testStrict(7) === 'Equal');
```
2018-09-30 22:01:58 +00:00
2021-03-03 00:12:12 +00:00
`testStrict("7")` should return the string `Not Equal`
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(testStrict('7') === 'Not Equal');
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
You should use the `===` operator
```js
assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
// Setup
function testStrict(val) {
if (val) { // Change this line
return "Equal";
}
return "Not Equal";
}
testStrict(10);
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
function testStrict(val) {
if (val === 7) {
return "Equal";
}
return "Not Equal";
}
```