DEV Community

Discussion on: When lodash is too much

Collapse
 
anduser96 profile image
Andrei Gatej

Thank you for sharing!

I'd like to point out a case when comparing 2 objects with JSON.stringify() could lead to unexpected results:

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

Enter fullscreen mode Exit fullscreen mode

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.

Collapse
 
briancodes profile image
Brian

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

Collapse
 
davidlacarta profile image
David Lacarta

Thank you for point out it!