All quizzesEasy
Classes & Objects
Preview — 3 of 10 questions
Which keyword is used to define a class in JavaScript?
javascript
class Person {
constructor(name) {
this.name = name;
}
}Afunction
Bobject
Cclass
Dconstructor
How do you create an object from a class?
javascript
class Car {
constructor(brand) {
this.brand = brand;
}
}
let myCar = ______;ACar("Toyota");
BCar.new("Toyota");
Ccreate Car("Toyota");
Dnew Car("Toyota");
What is the purpose of the constructor method in a class?
javascript
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const p = new Person("Alice", 30);
console.log(p.name); // "Alice"
console.log(p.age); // 30ATo define static properties
BTo create private methods
CTo call parent class methods
DTo initialize object properties
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.