0

I can't really understand the console.log last output.

It prints:

constructor  -  ƒ Array() { [native code] }
speak  -  undefined
undefined

1) Why is speak - undefined? 2) Why there is the third output line - just - undefined? Where does it get from?

class Bar { 
    speak() { 
        let text = 'test';
        alert(text);
        return text;
    } 
}
var test = new Bar;

z = Object.getOwnPropertyNames(Object.getPrototypeOf(test));
console.log(typeof z, " - ", z);

console.log(z.forEach(function(e) { console.log(e, " - ", z[e]); }));

Please help. Thank you!

Alan Larimer
  • 589
  • 8
  • 24
innrVoice
  • 75
  • 1
  • 7

1 Answers1

1

You're checking z[e] instead of test[e]. z is an array of property names, and arrays do not have a speak property, unlike Bar objects, which do have a speak property.

That explains the speak - undefined line. The final standalone undefined is the return value of console.log itself: Chrome/Firefox console.log always appends a line saying undefined

apsillers
  • 112,806
  • 17
  • 235
  • 239