>>> var par = {a: 1, b: 2}; undefined >>> var ch = Object.create(par); undefined >>> delete ch.a true >>> ch Object { a=1, b=2}
You misunderstood what delete returns:
Throws in strict mode if the property is an own non-configurable property (returns false in non-strict). Returns true in all other cases. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete)
delete ch.a tries to locate the property a in ch, fails (since ch doesn't have such own property), does nothing and happily returns true. If you wrote delete ch.foobar, the result would be the same. If however, you tried a non-configurable property (e.g. delete ch.__proto__), the result would be false.
delete ch.a
a
ch
true
delete ch.foobar
delete ch.__proto__
false
1.4m articles
1.4m replys
5 comments
57.0k users