-1

Say you have, an array and you're comparing particular elements of that array (with an index) to another array. It returns false although the values of the elements are the same. Why is that?

const arr1 = [1, 3, 5, 7];
[arr1[0], arr1[1]] === [1,3] // false
Chopin
  • 1
  • 1
    Duplicate of [How to compare arrays in JavaScript?](https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript) – esqew May 21 '22 at 04:53
  • From [a similarly helpful SO answer](https://stackoverflow.com/a/886053/269970): "*The default equality operator in JavaScript for Objects yields true when they refer to the same location in memory.*" What you are comparing with `===` in your example above will **not** refer to the same location in memory and thus will not be considered equivalent when using the `===` operator. The linked duplicate provides strategies to combat this concept. – esqew May 21 '22 at 04:56

0 Answers0