const age = Number(ageStr)
const result = "50" - 20; // 30
default implementation of this method, like the toString method is useless
returns the object on which this method is called.
new Date().valueOf(); // 1675526929129
null
undefined
NaN
0
,-0
,0n
false
""
This operator is infamous because many resources online
JavaScript developers, in general, discourage its use because of its coercive behavior.
If the values being compared are of the same type, then perform the strict equality comparison⁶⁶ ===
If one value is undefined or null and the other value is also undefined or null, return true console.log(null === undefined); // false
so only check for either null or undf
If one or both values are objects, they are converted into primitive types, preferring the number type
If both values are primitives but are of different types, convert the types until they match, preferring the number type for coercing values
const someVal = {};
if (someVal == true) {
console.log("true");
} else {
console.log("false");
}
// else
// 1. rule 4: someVal == 1
// 2. rule 4: "[obj Obj]" == 1
// 3. rule 4: "NaN" == 1
// 4. rule 4: NaN == 1
const someVal = {};
if (someVal) {
console.log("true");
} else {
console.log("false");
}
// true
console.log([13] == 13);
// single element coerced -> "13", true
console.log([1] < [2]);
// true
console.log([undefined] == 0);
//"" == 0 -> 0 = 0 -> true
console.log([] == ![]);
// Not operator takes precedence over ==
// 1) [] -> true -> ! -> false
// 2) [] == false -> [] == 0 -> "" == 0
// 3) 0 == 0 = true
console.log(!!"true" == !!"false");
//!!+string == !!+string
//!!true == !!true -> true