Javascript Object Check Property Existence via hasOwnProperty()

Description

Javascript Object Check Property Existence via hasOwnProperty()


// Demonstrating hasOwnProperty()
person = {name:"Elvis"};

// First we test for a known property
console.log( person.hasOwnProperty('name') );    // true

// Now we test for one that doesn't exit
console.log( person.hasOwnProperty('age') );      // false

// Now we test for one that exists but is inherited!
console.log( person.hasOwnProperty('hasOwnProperty') );      // false



PreviousNext

Related