What will be output of following code:
class User { constructor(name) { this.name = name; } greet() { console.log(`Hello ${this.name}`); } } console.log(typeof User); console.log(User.prototype); console.log(User.prototype.constructor); console.log(Object.getOwnPropertyNames(User.prototype));
This challenge tests your knowledge about how "class" syntax actually do under the hood.
Select one of the following:
function { constructor: [Function: User], greet: [Function: greet] } [Function: User] ['constructor', 'greet']
typeof User
:
typeof User
will return `"function".User.prototype
:
constructor
and greet
. The constructor
property references the User
function itself.User.prototype.constructor
:
User
function, indicating that the constructor
property points to the User
function.Object.getOwnPropertyNames(User.prototype)
:
User.prototype
, which are constructor
and greet
.class User {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello ${this.name}`);
}
}
console.log(typeof User);
console.log(User.prototype);
console.log(User.prototype.constructor);
console.log(Object.getOwnPropertyNames(User.prototype));
function
{
constructor: [Function: User],
greet: [Function: greet]
}
[Function: User]
['constructor', 'greet']