0 votes
in JavaScript by
What's the output?
class Person {
  constructor(name) {
    this.name = name;
  }
}

const member = new Person('John');
console.log(typeof member);
  • A: "class"
  • B: "function"
  • C: "object"
  • D: "string"

1 Answer

0 votes
by

Answer: C

Classes are syntactical sugar for function constructors. The equivalent of the Person class as a function constructor would be:

function Person(name) {
  this.name = name;
}

Calling a function constructor with new results in the creation of an instance of Persontypeof keyword returns "object" for an instance. typeof member returns "object".

Related questions

+1 vote
asked Feb 24 in JavaScript by DavidAnderson
0 votes
asked Mar 12 in JavaScript by DavidAnderson
...