0

Can someone explain why the value of result in the following code is false?

const o = { name: "Brendan" }; const s = JSON.parse(JSON.stringify(o)); const result = s === o; I thought the value of result would be true since parse recreates the object after stringify converts o to JSON text. Thanks

31st May 2020, 6:14 AM
Syed Zaidi
Syed Zaidi - avatar
2 ответов
+ 1
It does, it recreates an object which looks the same, but is not the same object. If you compare them by attributes, though, the comparison will be true. Try: s.name === o.name
31st May 2020, 6:34 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Thank you for your response - I really appreciate it. I guess then the point of confusion for me is the meaning of === in this context - I realize that the recreation is a new object with identitical property/value pairs, but my understanding was that the === comparison operator was checking to see if two variables/arrays/data type were of equal value and data type, not that they are identical variables or containers - my apologies, still a beginner and trying to wrap my head around this.
31st May 2020, 6:48 AM
Syed Zaidi
Syed Zaidi - avatar