When we retrieve the descriptor of an primitive type like the example below this paragraph we specify an integer as the object(which becomes the value of the property as well) and we specify the key as well which is '0'. Now because we specified an integer as the key would this mean that from ES2015 onwards, the primitive type is considered an array?
var e = Object.getOwnPropertyDescriptor([50], 0);
value of 'var e':
{
configurable: false,
enumerable: true,
value: 50,
writable: false
}
Or in the next example we pass in a string value:
var e = Object.getOwnPropertyDescriptor("hello", 0);
Which yields somewhat different results:
configurable: false
enumerable: true
value: "h"
writable: false
Now if we pass in a string it is treated as an array as well. But it appears that only the first character is being preserved as the value. Why does this happen as well?
Stringis simply an array of bytes. In JavaScript and other higher level languages,Stringis an array of bytes with a sort of wrapper around it to give it more functionality. Plus these two things are crucial for text manipulation which is used in countless places across the internet."hello"[0] === "h"Stringclass is different from the primitivestring- js just tends to coerce between them in many cases, for example, inObject.entries('abc'), thestring'abc'is converted to an objectnew String('abc')