javascript hasownproperty
var person = {	
  	"first_name": "Bob",
	"last_name": "Dylan"
};
person.hasOwnProperty('first_name'); //returns true
person.hasOwnProperty('age'); //returns falsejavascript hasownproperty
var person = {	
  	"first_name": "Bob",
	"last_name": "Dylan"
};
person.hasOwnProperty('first_name'); //returns true
person.hasOwnProperty('age'); //returns falsehasOwnProperty
//
//2021 - Object.hasOwn as a replacement for Object.hasOwnProperty()
//As other answers indicated, hasOwnProperty will check for an object own properties in contrast to in which will also check for inherited properties.
//There is a new alternative method called Object.hasOwn() and is intended to be a replacement for Object.hasOwnProperty()**
const person = { name: 'dan' };
console.log(Object.hasOwn(person, 'name'));// true
console.log(Object.hasOwn(person, 'age'));// false
const person2 = Object.create({gender: 'male'});
console.log(Object.hasOwn(person2, 'gender'));// false
 Run code snippetCopyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us
