codejump

Advanced OOP

Preview — 3 of 10 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
B42 and false
Cundefined 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
BTypeError
C"Alice" and null
D"Alice" and "Property age not found"

Sign up free to play

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