Object.hasOwn Playground

Owned or inherited? Four ways to ask about your own object and key: which can be fooled, and by what? An interactive Object.hasOwn playground: change the…

Why it matters

Checking property ownership is everywhere: JSON data, config, looping over objects. The old ways give subtle bugs: prototype-less objects from a library, a field named "hasOwnProperty", a legitimate 0 or undefined. Object.hasOwn removes that whole class of bugs.

The key idea

The three old ways have traps; Object.hasOwn has none

Common mistakes

Try it in this playground