Curious about the following two cases:
First:
const key = 2;
const obj = { "2": "stackoverflow" };
obj[key]; //results in "stackoverflow" but the key is 2 and not "2"
Second:
//Vice versa case
const otherKey = "21";
const otherObj = { 21: "youtube" };
otherObj[otherKey]; //results in "youtube" but the key is "21" and not 21
My conclusion:
That since keys should be string and while finding key
(when key is seemingly a number) existence in Javascript objects it does so by type-conversion comparison and not by strict or a string conversion.
Is there more to this why these cases work and am more interested in the how bit of that?