All quizzesMedium
Inheritance & Prototypes — Series 3
Preview — 3 of 10 questions
What is logged?
javascript
class A {
hello() {
return 'A';
}
}
class B {
hello() {
return 'B';
}
}
const obj = new A();
Object.setPrototypeOf(obj, B.prototype);
console.log(obj.hello(), obj instanceof A, obj instanceof B);AA true false
BB false true
CB true true
DTypeError: Cannot set prototype of an instance
What is logged?
javascript
class Widget {
render() {
return 'base';
}
}
const w = new Widget();
w.render = () => 'own';
console.log(w.render());
delete w.render;
console.log(w.render());Aown, undefined
Bbase, base
Cown, TypeError: w.render is not a function
Down, base
What is logged?
javascript
class Base {
static describe() {
return 'Base';
}
get info() {
return 'base';
}
}
class Child extends Base {
static describe() {
return super.describe() + ' -> Child';
}
get info() {
return `${super.info}+child`;
}
}
console.log(Child.describe(), new Child().info);ABase -> Child base+child
BBase -> Child undefined+child
CChild -> Child base+child
DTypeError: super is only allowed in a constructor
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.