I understand that the following code wraps a number into an object:
var x = Object(5);
I therefore expect and understand the following:
alert(x == 5); //true
alert(x === 5); //false
However, I also understand that an object is a list of key/value pairs. So I would have expected the following to be different:
alert(JSON.stringify(5)); //5
alert(JSON.stringify(x)); //5
What does the structure of x look like? And why does it not appear to be in key/value pair format?
JSON.stringify(), is that right?JSON.stringify()in your question is the result of how that particular API works. It explicitly understands that Number instances should be treated as numeric values in the resulting JSON.primitiveValueproperty, where the value is5, it's just like Pointy explains, some API's understand the difference between a "regular" object, and an object just holding a primitive value.