3
var mString = new String('A');

console.log(typeof mString); // object

console.log(mString instanceof String); // true

console.log(mString instanceof Object); // true

console.log(mString.__proto__ === String.prototype); // true

console.log(mString.__proto__.__proto__ === Object.prototype); // true 

Now, why

console.log(String.__proto__.__proto__ === Object.prototype); // true

and not

console.log(String.__proto__ === Object.prototype); // false

when walking up the prototype chain?

What is between String and Object prototypes?

2
  • Between a String instance and the Object prototype is the String prototype Commented Dec 4, 2017 at 21:37
  • 1
    Don't use the deprecated .__proto__ getter. Use Object.getPrototypeOf instead. Commented Dec 4, 2017 at 21:44

2 Answers 2

2
Function.prototype === String.__proto__ //true

It's a function's prototype, because String is a constructor function.

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

3 Comments

Its also worth noting that this is true for all classes not just String. For example (class A {}).__proto__ === Function.prototype is true
Because classes are just syntactic sugar over function constructors.
Awesome. Thanks, guys.
-1

When you use instanceof Object it means that the variable is either an Object or "extends" an Object.

As mentioned here "The instanceof operator tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object."

So mString.__proto__ is not equal to Object.prototype, but it Object.prototype is indeed higher on the prototype chain, that's why they are not equal. The String prototype inherits the Object prototype.

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.