1

Can somebody please explain the following passage from YDKJS Up & Going to me like I am five:

You should take special note of the == and === comparison rules if you're comparing two non-primitive values, like objects (including function and array). Because those values are actually held by reference, both == and === comparisons will simply check whether the references match, not anything about the underlying values. For example, arrays are by default coerced to strings by simply joining all the values with commas (,) in between. You might think that two arrays with the same contents would be == equal, but they're not:

var a = [1,2,3];
var b = [1,2,3];
var c = "1,2,3";
a == c;       // true
b == c;       // true
a == b;       // false

What is meant by "references"? Does this mean where the array is held in memory?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Possible duplicate of [How to explain object references in ECMAScript terms?](https://stackoverflow.com/q/23554770/1048572) – Bergi Dec 26 '20 at 16:54

1 Answers1

0

well yeah, you see when you create array named 'arr' for example. your memory look like this: stack heap array example

so reference comparison actually check if the array reference point the same array in the heap. stack is for value types and references.

  • With that being said, is it impossible for a non-primitive data-type to have true equality when compared to another non-primitive? – Zachary Adams Nov 27 '17 at 17:30