JavaScript Object Comparison: Reference vs Value

JavaScript Interview Question What will be the output? const obj1 = { name: "Suman" }; const obj2 = { name: "Suman" }; console.log(obj1 == obj2); console.log(obj1 === obj2); At first glance, many developers expect the result to be true because both objects have the same values. But JavaScript compares objects by reference, not by value. Even if two objects contain identical properties, they are stored in different memory locations. So what do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #FrontendArchitecture #ProductBasedCompany

false false Because in JS objects are compared by reference not by value. Even though obj1 and obj2 have identical properties they are stored at different memory locations so both == and === return false.

See more comments

To view or add a comment, sign in

Explore content categories