0

When I do new String("hello") in my console I get the following result:

String {"hello", length: 5}

The first value in the String Object that was returned doesn't have a key.

Since objects are associative/hash arrays i.e. defined and created with keys and values how is the String constructor returning an object with a value without key?

1 Answers1

1

It doesn't.

You're just misinterpreting the console's visualisation of a string object and assuming it is expressing it in the form of object literal syntax. If it would, you would see:

 { 0: "h", 1: "e", 2: "l", 3: "l", 4: "o", length: 5, __proto__: String }

But thats certainly quite unreadable, so they probably changed the way of visualizing to make it easier to read.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335