Expected '===' and instead saw '=='
18 useEffect(st);
19 const toggle = () => {
20 let ret = "light";
21 if (theme == "light") {22 ret = "dark";
23 }
24 setThemeStorage(ret);
Expected '===' and instead saw '=='
14 });
15 return (
16 <div>
17 <NextNProgress options={{ showSpinner: false }} showSpinner={false} color={`${theme == "dark" ? "#1d4ed8" : "#3b82f6"}`}/>18 <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
19 <link rel="preconnect" href="https://fonts.googleapis.com"/>
20 <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true"/>
Expected '===' and instead saw '=='
10 let l = [];
11 imageSrcs.forEach((imageSrc, i) => {
12 l.push(
13 <img className={`${styles.imageCarouselImage} ${(index == i) ? styles.imageCarouselActiveImage : styles.imageCarouselInactiveImage}`} src={imageSrc} key={i}/>14 )
15 });
16 setImages(l);
Description
It is considered good practice to use the type-safe equality operators ===
and !==
instead of their regular counterparts ==
and !=
.
The strict equality operators (===
and !==
) use the strict equality comparison algorithm to compare two operands.
- If the operands are of different types, return
false
. - If both operands are objects, return
true
only if they refer to the same object. - If both operands are
null
or both operands areundefined
, returntrue
. - If either operand is
NaN
, returnfalse
. - Otherwise, compare the two operand's values:
- Numbers must have the same numeric values.
+0
and-0
are considered to be the same value. - Strings must have the same characters in the same order.
- Booleans must be both
true
or bothfalse
.
- Numbers must have the same numeric values.
The most notable difference between this operator and the equality (==
) operator is that if the operands are of different types, the ==
operator attempts to convert them to the same type before comparing.
Bad Practice
a == b
foo == true
bananas != 1
value == undefined
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null
Recommended
a === b
foo === true
bananas !== 1
value === undefined
typeof foo === 'undefined'
'hello' !== 'world'
0 === 0
true === true
foo === null