Comparing JavaScript hasOwnProperty() vs in operator​

Benchmark created on


Setup

const person = {
  name: "John",
  age: 30,
};

Test runner

Ready to run.

Testing in
TestOps/sec
Check property using hasOwnProperty() method
console.log(person.hasOwnProperty("name")); 
ready
Check property using in operator
console.log("name" in person);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.