The browser storage localStorage is not available. Either your browser does not support it or you have disabled it or the maximum memory size is exceeded. Without localStorage your solutions will not be stored.
Strict equality
Two values can be checked for strict equality. The result of such a comparison is either
true
,
the two values are equal, or false
, the two values are not equal. The operator for strict equality
is ===
.
let language = 'JavaScript';
let x = 10;
let c1 = language === 'Java';
let c2 = x === 10;
let c3 = x === '10';
The first comparison results in false
, because language
does not have the value
'Java'
. So c1
is false
. The second comparison results in true
,
because the value of x
equals 10
. So c2
is true
.
In the case of strict equality, it is also important that the two compared values have the same data type.
c3
is false
, because different data types are compared here.
On the left side of the comparison is a number, on the right side a string.Exercise
Write a function
Example:
equals
that checks two values for strict equality.Example:
equals(1, 1)
should return true
and equals(1, 2)
should
return false
.
+ Hint
function equals(a, b) {
return ...
}
+ Solution
function equals(a, b) {
return a === b;
}