title: JavaScript hasOwnProperty vs typeof
body: <p>I've searched a lot on Google but couldn't found where I was looking for:</p>
  
  <p><a href="https://stackoverflow.com/questions/17150396/benefit-of-using-object-hasownproperty-vs-testing-if-property-is-undefined">Benefit of using Object.hasOwnProperty vs testing if Property is undefined</a></p>
  
  <p><a href="http://jsperf.com/hasownproperty-vs-in-vs-undefined/12" rel="nofollow noreferrer">jsperf speedtest</a></p>
  
  <p><a href="https://stackoverflow.com/questions/595766/how-to-determine-if-native-javascript-object-has-a-property-method">How to determine if Native JavaScript Object has a Property/Method?</a></p>
  
  <p>.. and a lot of other websites, but this is not where I am looking for. My real question is: </p>
  
  <p><strong>Why does <code>hasOwnProperty</code> not find a method in his super class(prototype)? And why does somebody even use <code>hasOwnProperty</code>? It's much slower than <code>typeof</code> and it doesn't work if you are working with inheritance.</strong></p>
  
  <p>.. second question:</p>
  
  <p>In <a href="https://stackoverflow.com/questions/595766/how-to-determine-if-native-javascript-object-has-a-property-method">this</a> question Barney answers that you have to use <code>if ('property' in objectVar)</code> to check if a property exists, but doesn't explain why. Does someone knows why you would use this structure?</p>
  
  <pre><code>var objA = function(){};
  
  objA.prototype.alertMessage = function(){
          return 'Hello A';
  };
  
  var objB = function(){
      this.hello = function(){
          return 'hello';
      };
  };
  
  // Inheritance
  objB.prototype  = Object.create(objA.prototype);
  objB.prototype.constructor = objA;
  
  var test = new objB();
  
  if (test.hasOwnProperty("alertMessage")){
      console.log("hasOwnProperty: " + test.alertMessage());
  }
  
  if (typeof test.alertMessage === "function"){
      console.log("typeof: " + test.alertMessage());
  }
  
  if (test.hasOwnProperty("hello")){
      console.log("hasOwnProperty: " + test.hello());
  }
  
  if (typeof test.hello === "function"){
      console.log("typeof: " + test.hello());
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/GuyT/8wy4so8m/" rel="nofollow noreferrer">Check out the jsFiddle</a></p>