1

Why does String have a prototype.length as well as clearly generate a direct length property (that must’ve come from somewhere in the String constructor function)?

enter image description here

adiga
  • 34,372
  • 9
  • 61
  • 83

1 Answers1

0

That's just how it is. From the specification:

The String prototype object:

  • is a String exotic object and has the internal methods specified for such objects.
  • has a [[StringData]] internal slot whose value is the empty String.
  • has a length property whose initial value is 0 and whose attributes are { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

This might be considered an accident or not, but it's too late to change now. See also Why is Boolean.prototype a Boolean object again? (And same for String and Number, but not Date or RegExp?).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375