hasOwnProperty
A check that tells whether an object has a property itself, rather than inheriting it, even when its value is undefined.
In more detail
It distinguishes { bio: undefined } from {}, which a simple comparison with undefined cannot do. Object.hasOwn(obj, "key") is the modern, safer form.
Related terms
- exactOptionalPropertyTypes — The compiler option that forbids setting an optional property to undefined explicitly, so it must be omitted or given a real value.
- in operator — The JavaScript operator "key" in obj, which checks whether an object has a property and lets TypeScript narrow a union by it.
Taught in
- void, undefined And null: Exact Optional Property Types — Production TypeScript