How does string equality work in JavaScript?

后端 未结 3 989
我寻月下人不归
我寻月下人不归 2020-12-10 03:40

There are plenty of tutorials for == and === so please don\'t guide me to a basic tutorial, my question is a bit more specific:

For example

3条回答
  •  醉话见心
    2020-12-10 04:06

    String literals, which are primitive value types, are different from new String objects, which are entities with distinct references wrapping those values. See Predefined Core Objects in Mozilla's JavaScript docs for details.

    So you're right in that comparison is handled differently for literals and for objects, simply because one compares their values while the other compares references.

提交回复
热议问题