Every object has its own prototype?

Since every object in JS has its prototype, why does typeof father.prototype returns undefined instead of object?

	function Family(name) {
	  this.name = name;
 let father = new Family ('Rocky')
	console.log(typeof Family.prototype);		// object
 console.log(typeof father.prototype);		// undefined
 console.log(typeof Object.prototype);		// object
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52

Challenge: Understand Where an Object’s Prototype Comes From

Link to the challenge:

This is confusing for sure. Basically, there are different types of “objects” in JS. The standard JS object Object (capital O is important here) is really a function. (Go ahead, type typeof Object in the JS console and see what it says). Only functions with constructors have a prototype property. The function Family you created is technically a constructor function, so it will also have a prototype property. But when you create an instance of an object, that object does not have a prototype property because it is not a function. If you did a console.log(typeof father) you would see that it returns “object”. That doesn’t mean that father doesn’t have a prototype though, just not a prototype property. There are ways to get this object’s prototype, but using the prototype property isn’t one of them.

So that’s why you are getting undefined for father.prototype. Yes, this is extremely confusing and that’s why the new class syntax is so much nicer, it pretty much hides all this nonsense.

Disclaimer: I am not an expert on JS prototypes so not everything I said above may be 100% correct, but I think I got it right for the most part.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.