r/transprogrammer • • Jul 16 '24

Javascript bad

Post image
104 Upvotes

35 comments sorted by

View all comments

Show parent comment

3

u/TDplay Jul 17 '24

since most other languages default to reference equality for reference types

It is a surprising behaviour, regardless of how many languages do it. Any empty array is semantically the same thing as any other empty array.

Having == perform a pointer comparison only really makes sense when the types you're dealing with are raw pointers (since there is no better notion of equality for raw pointers). For other types, it is a confusing and unexpected behaviour - if you write ==, you almost certainly want to check for semantic equality.

1

u/retrosupersayan JSON.parse("{}").gender Jul 17 '24

I guess it depends on how your intuition is calibrated. My first language was Java, which doesn't allow operator overloading, so == can only be reference equality.

2

u/definitelynotagirl99 Jul 18 '24

not explicitly diffrentiating between values and references is the real issue javascript is having in this context.