29/30 Is my code bad?


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

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



var prototypeType = typeof Object.prototype;


Your code is fine, and the output is correct and as expected. A prototype is an object, and Object.prototype.hasOwnProperty("hasOwnProperty") is indeed true.

Something you will read often is that everything in JavaScript is an object, tracing all the way up to the DOM, itself. When we create an object, it also has a prototype object which properties help to define the object instance. All objects are descended from Object and all objects inherit from Object.prototype.

The prototype object is how we are able to add properties to both built in objects and those we create in our program (custom objects) that apply across the range of instances that inherit from the respective object. Without a prototype object, each instance would need to have its own methods and properties defined.

Think of the prototype as being a list of properties and methods that don't have to be directly tied to an object. Our object instances don't inherit directly from Object, but from its prototype object. In being structured this way, new object instances automatically have the same set of methods and properties at their disposal. Let's work with the example in your code...

var myObject = {
    name: "some object",
    inherits: "Object.prototype"
console.log(myObject.hasOwnProperty('inherits')); // true

In the above, myObject inherits hasOwnProperty from Object.prototype just for having been an object instance. We didn't have to go to any extra length to link to that method.

The above is a plain object so has only the one prototype. Were we to define the instance with a constructor function, we could extend the prototype for that object.

function Person(name, age){
    this.name = name;
    this.age = age;
Person.prototype.attributes = function(){
    return "Name: "+ this.name + ", Age: " + this.age;
var me = new Person("Wee Gillis", 19);
var he = new Person("John Doe", 25);

me.attributes(); // Name: Wee Gillis, Age: 19
he.attributes(); // Name: John Doe, Age: 25

Notice that both instances have an attributes method? It is a direct property of neither instance. No matter how many instances we invoke, they will all have this method.


Thank both of you so much for your responses. I feel the name of the exercise, "So Meta I Can't Take It!" is an pun/rhyme to "So mad I can't take it!" because I will forever have a 99% in Codecademy's JavaScript course. I like my ninety-nine though.


I had the same problem. When I removed the parenthesis from the typeof variable definition the problem went away: from this: var prototypeType = (typeof Object.prototype);
to this: var prototypeType = typeof Object.prototype;



typeof is a built in operator. It is not a function, but takes input in either form, literal, or enclosed in a parameter list.

foo = function () {};

typeof (9)       =>  'number'
typeof('string") =>  'string'
typeof true      =>  'boolean'
typeof foo       =>  'function'

What we cannot do is write the entire expression in parentheses, as you have discovered.