Hacker News new | ask | show | jobs
by kazinator 745 days ago
What about the identity side of it? Does the JS specification say that an operation like "a" + "b" is not required to create a new object? Regardless of whether there is such a spec, you can write code that is sensitive to the difference.
1 comments

In fact, you cannot. But I encourage you to try!
It looks like JS doesn't expose equality operator which can distinguish different strings. Thus "abc" and "abc" are the same object, no matter how they are produced, even if under the hood they are separate instances.
Pretty much, though some would contest calling strings “objects”.

The spec indeed goes through some trouble to ensure they are pure value-types and do not exhibit any reference-like semantics, for instance by prohibiting their use as keys of WeakMaps and WeakSets - along with numbers, booleans, nullish values, and bignums.