1

Strings are immutable. That means when I change a string - new string reference created instead.

If so how "foo" === "foo" give me true value?

The === compares by reference location in the memory and not by the value.

So, the first string should be new reference somewhere is the memory and the another foo should be save somewhere else in the memory.

How it is possible?

Jon Sud
  • 10,211
  • 17
  • 76
  • 174
  • 4
    It doesn't compare "by reference". It compares *by type and value*. – deceze Feb 08 '21 at 13:00
  • 1
    "*The === compares by reference location in the memory and not by the value.*" that has ***never*** been the case. The comparisons are *always* done by value. [JavaScript is a pass-by-value language](https://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language). The value of a string is its content, the value of *an object* is its reference. – VLAZ Feb 08 '21 at 13:01

0 Answers0