Penguins, Properties, and the Prototype


Why do we not encapsulate console.log(emperor.numLegs); within a pair of { }?

function Penguin(name) { = name;
    this.numLegs = 2;

// create your Emperor class here and make it inherit from Penguin
function Emperor(name) { = name;
Emperor.prototype = new Penguin();
// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("Betty");


Why do you think pair of {} would be necessary, what purpose does it serve?


This is why I am asking the question, elv1nas. Would you care to provide an answer?


console.log(emperor.numLegs); is just a simple statement that prints object's property value. I don't understand why you think curly brackets are necessary here. There is always a reason to use them:

To wrap function body, to create object literals and if/else statements, loops and etc.


I thought the curly brackets were necessary because up to this point, the exercises were using them. There was no explanation otherwise in any of the exercises.


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