Recently I cam across an interesting scenario while working with javaScript objects.
If we add any strings in an object it gets saved in the order that we added them
let obj = {};
obj[“z”] = true;
obj[“a”] = true;
obj[“c”] = true;
console.log(Object.keys(obj)) // [“z”,”a”,”c”]
But in the case of adding numbers, it seems to sort it by default
let obj = {};
obj[9] = true;
obj[1] = true;
obj[5] = true;
console.log(Object.keys(obj)) // [1,5,9]
What is the reason that this is happening???