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

Currently exploring Frontend (React.js) opportunities | 2.5 YOE | Serving notice period Open to referrals and opportunities. Happy to share my resume 🙌

Ans1. True because == is loose equality check, it compare value only.2. False because === is strict equality check, it compare datatype or reference also.

Ans : console.log(obj1 == obj2); = false console.log(obj1 === obj2); = false Both have the same data, but their memory locations are different.

At first glance many developer expect the result to be true which is not correct then surely the answer will be false

Primitive (string, number, boolean) → value compare Objects, arrays, functions → reference compar

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories