Title: JavaScript check if object has inherited property
Tags: javascript;inheritance
Question: ```function Employee(name, dept) {
    this.name = name || "";
    this.dept  = dept || "general";
}

function WorkerBee(projs) {
    this.projects = projs || [];
}

WorkerBee.prototype = Object.create( Employee.prototype );

function Engineer(mach) {
    this.dept = "engineering";
    this.mach = mach || "";
}

Engineer.prototype = Object.create(WorkerBee.prototype);
var jane = new Engineer("belau");

console.log( 'projects' in jane );
```

Trying to check if ```jane``` inherited the ```projects``` property.

Outputs ```false```. Why?


Here is the accepted answer: ```
  Outputs ```false```. Why?
```

Because ```this.projects``` is set inside ```WorkerBee```, but that function is never executed. 

This is the same issue as in your previous question: JavaScript inheritance Object.create() not working as expected

Comment for this answer: Just realized that. What confused me was the use of `new` instead of `Object.create()`

Here is another answer: If you are testing for properties that are on the object itself (not a part of its prototype chain) you can use .hasOwnProperty():

```if (x.hasOwnProperty('y')) { 
  // ......
}
```

Object or its prototype has a property:

You can use the in operator to test for properties that are inherited as well.

```if ('y' in x) {
  // ......
}
```

Comment for this answer: `x = "test"; try { if ('indexOf' in x) { console.log('it is correct answer'); }} catch (e) {console.log('it is wrong answer, actually'); }`
Comment for this answer: While you are right, this doesn't answer the OP's question.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:06/23/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<javascript><inheritance>', 'Title': 'JavaScript check if object has inherited property', 'ViewCount': 1569, 'id': 31015374, 'user_AboutMe': '', 'user_AccountId': 2009968.0, 'user_DisplayName': 'Robert', 'user_Reputation': 9684.0, 'user_Views': 1121.0, 'user_id': 1798677.0}}