Object.prototype.hasOwnProperty vs In

Edit on GitHub

Setup

var object = {
  value: 5
};

Tests

  • Object.prototype.hasOwnProperty

    if (object.hasOwnProperty('value')) {
      object.value == 1;
    }
  • In

    if ('value' in object) {
      object.value == 1;
    }