hasOwnProperty()

ES3+

Returns a boolean indicating whether the object has the specified property as its own property.

Syntax

obj.hasOwnProperty(prop)

Parameters

prop string

The property name to check

Return Value

boolean

true if the object has the property, otherwise false

Examples

JavaScript
const obj = { name: 'John' };
console.log(obj.hasOwnProperty('name'));
console.log(obj.hasOwnProperty('age'));
console.log(obj.hasOwnProperty('toString'));
Output:
// true false false

Related Methods