===
) 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.
If the values being compared have different types, they are considered unequal, and the strict equality operator will return false.
Examples
3 === 3 // trueIn the second example,
3 === '3' // false
3
is a Number
type and '3'
is a String
type.
if
statement so the function will return "Equal" when val
is strictly equal to 7
testStrict(10)
should return "Not Equal"
testString: 'assert(testStrict(10) === "Not Equal", "testStrict(10)
should return "Not Equal"");'
- text: testStrict(7)
should return "Equal"
testString: 'assert(testStrict(7) === "Equal", "testStrict(7)
should return "Equal"");'
- text: testStrict("7")
should return "Not Equal"
testString: 'assert(testStrict("7") === "Not Equal", "testStrict("7")
should return "Not Equal"");'
- text: You should use the ===
operator
testString: 'assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0, "You should use the ===
operator");'
```