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