Expected '===' and instead saw '=='
112 }
113
114 // Toggle the state of the "display" style
115 elem.style.display = disp == 'block' ? 'none' : 'block';116
117 return false;
118}
Expected '===' and instead saw '=='
78{
79 for (var i = 0; i < element.childNodes.length; i ++)
80 {
81 if (element.childNodes[i].nodeName == tagName) 82 {
83 return element.childNodes[i];
84 }
Expected '===' and instead saw '=='
58 // Also show the selected content div, and hide all others.
59 for (var id in contentDivs)
60 {
61 if (id == selectedId) 62 {
63 tabLinks[id].className = 'active';
64 contentDivs[id].className = 'content';
Expected '!==' and instead saw '!='
41
42 for (var id in contentDivs)
43 {
44 if (i != 0) 45 {
46 console.log(contentDivs[id]);
47 contentDivs[id].className = 'content hide';
Expected '===' and instead saw '=='
29 tabLinks[id].onfocus = function () {
30 this.blur()
31 };
32 if (i == 0) 33 {
34 tabLinks[id].className = 'active';
35 }
Expected '===' and instead saw '=='
10 console.log(tabListItems);
11 for (var i = 0; i < tabListItems.length; i ++)
12 {
13 if (tabListItems[i].nodeName == "LI") 14 {
15 var tabLink = getFirstChildWithTagName(tabListItems[i], 'A');
16 var id = getHash(tabLink.getAttribute('href'));
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