Are arrays and objects with numeric properties equal in javascript?

288 Views Asked by At

Can someone explain to me why the following is true:

let foo = { 
    A: [ 1, 2 ] 
}
let bar = {
   "A": {
      "0": "1",
      "1": "2"
   }
}
assert.deepEqual(foo, bar);
1

There are 1 best solutions below

0
meskobalazs On BEST ANSWER

As the documentation says:

Only enumerable "own" properties are considered. The assert.deepEqual() implementation does not test the [[Prototype]] of objects or enumerable own Symbol properties. For such checks, consider using assert.deepStrictEqual() instead.

The assert.deepStrictEqual() function does check the prototype too, and

assert.deepStrictEqual(foo, bar);

will return false.