Skip to content

OutputNot attempted

Own property shadows the prototype

const proto = {
greet() {
return 'proto';
},
};
const obj = Object.create(proto);
obj.greet = () => 'own';
console.log(obj.greet());
delete obj.greet;
console.log(obj.greet());
delete obj.greet;
console.log(obj.greet());

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

Lookup checks the object itself first, then up the chain. delete only removes OWN properties, so the second delete does nothing; the prototype method stays.