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?

9
  • 3
    Where are you seeing that output? Commented Jul 30, 2018 at 7:40
  • 3
    Which browser? That's not what i get in Chrome. I get a char array with the proper length and the String prototype. Commented Jul 30, 2018 at 7:41
  • 1
    length: 0 ? But still: what you see in the console is not always what the objects look like in js Commented Jul 30, 2018 at 7:42
  • @Vipinkumar Singh: String is an array of characters. That is what the console outputs you if you expand the output. Commented Jul 30, 2018 at 7:46
  • 1
    @Vipinkumar Singh: Yes, you edited length from 0 to 5. Now it is equal. Commented Jul 30, 2018 at 7:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.