In below code snippet a==b return true, i.e they point to same memory location, hence they will have same value. I would like to know, how JS engine knows a===b is false. How is type information determined when 2 different types point to same memory location?
Edit 1: From comments it looks like my question might not be clear. I totally understand difference between == and === in terms of usage in JS language. I am more interested in knowing how JS engine saves type information for null and undefined. As per my understanding variables a & b point to same memory location that is why I get a==b, if this understanding is wrong, please correct me.
Edit 2: Ok I will put my question in another way. How typeof operator knows a is object and b is undefined despite having a==b.
var a = null;
var b = undefined;
console.log(a==b);
console.log(a===b);
console.log(typeof a);
console.log(typeof b);
===have to do with memory location?==operator performs type coercion, so no, they don't necessary point to the same memory.==returns true does NOT mean that they are on the same memory. The reason==returns true is because the specification says so. "If x is null and y is undefined, return true.". It has nothing to do with memory.1and"1"it is again the specification that says they should be true for==: "If Type(x) is Number and Type(y) is String, return the result of the comparison x == ! ToNumber(y)"