All quizzesEasy
Classes & Objects — Series 2
Preview — 3 of 10 questions
What is logged?
javascript
class Circle {
constructor(radius) {
this.radius = radius;
}
get area() {
return Math.PI * this.radius ** 2;
}
}
const c = new Circle(2);
console.log(c.area);
console.log(typeof c.area);A[Function: area], "function"
B12.566370614359172, "number"
Cundefined, "undefined"
DTypeError: c.area is not a function
What is logged?
javascript
class Counter {
count = 0;
increment() {
this.count += 1;
return this.count;
}
}
const c1 = new Counter();
const c2 = new Counter();
console.log(c1.increment());
console.log(c2.count);A1, 1
B0, 0
Cundefined, undefined
D1, 0
What is logged?
javascript
class Animal {}
class Dog extends Animal {}
const d = new Dog();
console.log(d instanceof Dog);
console.log(d instanceof Animal);
console.log(d instanceof Object);Atrue, true, true
Btrue, false, true
Ctrue, true, false
Dfalse, true, true
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.