e.g.
$ node
> [1, 2, 3] == [1, 2, 3]
false
Apologies if I am using "identical" and "equivalent" incorrectly.
console.log([1, 2, 3] == [1, 2, 3]);
I ask, because I am used to languages such as Ruby
$ irb
irb(main):001:0> [1,2,3] == [1,2,3]
=> true
...or Python
$ python
>>> [1,2,3] == [1,2,3]
True
... where the double equals is comparing the value of the expression
Because while they may have the same content, they don't point to the same reference in memory.
For more precision, imagine the following example
let arr1 = [1,2,3]
let arr2 = [1,2,3]
arr1 == arr2 //false
it makes sense, because the two arrays are different objects, even if they have similar values, for example if we then did
arr1.push(4)
only arr1 would change.
If you are looking for a solution to comparing arrays, you might find this thread useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With