Strict Equality With === 


Given 2 values x and y, the strict equality checks for equality in the following way:

x === y 

 

-> Check the types of x and y. If they are of different types, return false.



-> If x and y are numbers, it checks if either of x or y is NaN, and returns false if one is NaN.

 

-> If both x and y are either +0 or -0, return true. Otherwise, it also checks to see if they are the same number.



-> If x and y are both null or both undefined, it returns true.



-> If x and y are both booleans, strings, or symbols, then it compares them by value.



-> If x and y are both objects, it returns true if and only if they reference the same object. 

 

Abstract Equality With == 


Here is a brief overview of how the == operator compares if x and y are equal. 

 

-> If x and y are of the same type, check if x === y 


-> If x and y are both either null or undefined, return true. 

 

-> If x is a number and y is a string, convert y to a number and then compare using ===. Similarly, if x is a boolean or string, and y is a number, convert x to a number. 

 

-> If x or y is a boolean, convert the other value of a number and compare them. 

 

-> If x is an object and y is a symbol, string, or number, try to convert x to a primitive using valueof() and then compare using ===.