is-equal-shallow icon indicating copy to clipboard operation
is-equal-shallow copied to clipboard

The code should not check if value is primitive or not

Open lsmoura opened this issue 6 years ago • 1 comments

JavaScript non-primitive objects are memory references. So, if variables in two different objects point to the same memory reference, it should return true.

Take this code for example:

const shallow = require('is-equal-shallow');

const o = { foo: 'bar' };

const a = { a: o };
const b = { a: o };

console.log('a shallow-equal b?', shallow(a, b));

A and B are exactly the same, since the a key points to the same object. It's different from calling

const shallow = require('is-equal-shallow');

const a = { a: { foo: 'bar' } };
const b = { a: { foo: 'bar' } };

console.log('a shallow-equal b?', shallow(a, b));

Because they point to different objects.

Should the isPrimitive check be dropped from the test?

lsmoura avatar May 04 '18 13:05 lsmoura