Advanced OOP

Preview — 3 of 19 questions

What will the following code output?

javascript
const animal = {
  type: 'Animal',
  describe() {
    return `I am a ${this.type}`;
  }
};

const dog = Object.create(animal);
dog.type = 'Dog';
console.log(dog.describe());
A"I am a Animal"
B"I am a Dog"
Cundefined
DTypeError

What will the following code output?

javascript
const obj = {};
Object.defineProperty(obj, 'secret', {
  value: 42,
  enumerable: false,
});

console.log(obj.secret);
console.log(Object.keys(obj).includes('secret'));
A42 and true
Bundefined and false
C42 and false
DTypeError

What will the following code output?

javascript
const handler = {
  get(target, prop) {
    return prop in target ? target[prop] : `Property ${prop} not found`;
  }
};

const user = new Proxy({ name: 'Alice' }, handler);
console.log(user.name);
console.log(user.age);
A"Alice" and undefined
B"Alice" and "Property age not found"
C"Alice" and null
DTypeError

Sign up free to play

Answer all 19 questions (16 more), see explanations for every answer, and track your score.