Thank you for sharing!
I'd like to point out a case when comparing 2 objects with JSON.stringify() could lead to unexpected results:
JSON.stringify()
function isEqual(objectA, objectB) { return JSON.stringify(objectA) === JSON.stringify(objectB); } const a = { name: 'andrei', age: 18} const b = { age: 18, name: 'andrei' } console.log(isEqual(a,b)) // false
As far as I can understand, the order matters. I didn't know about this a while ago, so I thought it was worth sharing.
That's really one of the main reasons to use a utility library like lodash - there are a multitude of edge-cases that have been identified and fix over the years
lodash
Thank you for point out it!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for sharing!
I'd like to point out a case when comparing 2 objects with
JSON.stringify()
could lead to unexpected results:As far as I can understand, the order matters.
I didn't know about this a while ago, so I thought it was worth sharing.
That's really one of the main reasons to use a utility library like
lodash
- there are a multitude of edge-cases that have been identified and fix over the yearsThank you for point out it!