Comparing Two Objects in Javascript

Last Updated: February 25, 2022

You can compare two objects in Javascript to make sure there refer to the same instance

function Person(name){

var p1= new Person("John")
var p2= new Person("John")

console.log("Are these equal "+p1===p1)

You can see following output in browser console
>Are these equal? false

In this example, I am creating two objects with the same property but they are not equal.