29. So Meta I Can't Take It! - Printing correct output?

Hey, just wondering if the console is logging the correct things here! Thanks

Exercise: https://www.codecademy.com/courses/objects-ii/5/3?curriculum_id=506324b3a7dffd00020bf661

This is what the console logs:

// what is this "Object.prototype" anyway...?
var prototypeType = typeof Object.prototype;

// now let's examine it!
var hasOwn = Object.prototype.hasOwnProperty("hasOwnProperty");
1 Like

I’m assuming, I’m getting the same thing,

1 Like


A prototype is an early sample, model, or release of a product
built to test a concept or process or
to act as a thing to be replicated or learned from.
The word prototype derives from the Greek πρωτότυπον prototypon,
“primitive form”, neutral of πρωτότυπος prototypos,
“original, primitive”, from πρῶτος protos, “first” and τύπος typos, “impression”.


Inheritance and the Prototype Chain

Prototypal Inheritance is Dynamic

One of the most important advantages of prototypal inheritance is
that you can add new properties to prototypes after they are created.
This allows you to add new methods to a prototype
which will be automatically made available
to all the objects which delegate to that prototype.

This is not possible in classical inheritance
because once a class is created you can’t modify it at runtime.
This is probably the single
biggest advantage of
prototypal inheritance
over classical inheritance,
and it should have been at the top.


Prototypal inheritance matters.
It’s important to educate JavaScript programmers
on why to abandon the constructor pattern of prototypal inheritance
in favor of the prototypal pattern of prototypal inheritance.

We need to start teaching JavaScript correctly
and that means showing new programmers how to write code
using the prototypal pattern instead of the constructor pattern.

Not only will it be it easier to explain
prototypal inheritance using the prototypal pattern,
but it will also make better programmers


++++++++ a String type explained ++++++

why it should be Object.prototype.hasOwnProperty.
The hasOwnProperty Method is the only method
which will be fetched from the Object.prototype WITHOUT traversing
through the prototype Chain.

In the following link:

Under the Header:

The lookup time for properties that are high up on the prototype chain can have a negative impact on performance, and this may be significant in code where performance is critical. Additionally, trying to access nonexistent properties will always traverse the full prototype chain.

Also, when iterating over the properties of an object, every property that is on the prototype chain will be enumerated.

To check whether an object has a property defined on itself and not somewhere on its prototype chain, it is necessary to use the hasOwnProperty method which all objects inherit from Object.prototype.

hasOwnProperty is the only thing in JavaScript which deals with properties and does not traverse the prototype chain._


now to your case:
var prototypeType = typeof Object.prototype;
will leave you with a variable which has a VALUE of the string-type

As the string is created, you will get a present…the length Property
prototypeType.hasOwnProperty(“length”) ==> true.

From the String.prototype you will inherit the methods:

And as anything in the Javascript environment is an object
from the Object.prototype you inherit:
‘hasOwnProperty’ \<== this is a special one !!



You mean this?

Instead of :

function Person(name,age){

using the following?!

function Person(){



Thank you very much

1 Like

And then every Instance of Person
having the same name and age ???
and having hasOwnProperty being false…

ahhh i follow now really didn’t understand what the question was asking
many thanks, i was stuck on this one to but this helped me work out what they wanted.

I still haven’t really figured it can you try to explain me in your words this 2 cases in the code in a ‘beginner’ words. thanks :slight_smile: i know you are new too that’s why im asking you thanks again

I had to study it for about an hour or so, and I can’t easily explain it well, but if you study these, they should help you make sense of it:

Begin by referring to exercise 7 in the same lesson (Introduction to Objects II)
w3schools.com - JavaScript Object Prototypes - start here

Then read these (they are what made the concept really stick for me):
Mozilla Developer Network - Inheritance and the prototype chain
Mozilla Developer Network - Object.prototype.hasOwnProperty()

1 Like

In addition to Travism87’s helpful post, the following article helped me also understand the hasOwnProperty Method.

MSDN.Microsoft.com: hasOwnProperty Method article