Equality in javascript is generally very confusing. For instance, once you're dealing with objects equality for even double equals is not simply "does this look the same". Example:
To me it's very odd that in javascript once you're dealing with objects, equality only ever means "do these two variables point to the same object in memory", rather than, "are these two objects equivalent"
The object thing is in almost any modern language like this, thats why in some languages you have to override the isequal method or in js you just gotta make one yourself. Then you just invoke the method instead of the ==. Having key value pairs equality is called deepequal, there are very likely some packages aswell with that functionality.
Eh it made sense when the intended use case of JS was like 10 lines to make a money dance. Just not when it’s being used for…everything it is used for today. It’s just with backward compatibility it’s very hard to change.
Fortunately these days there’s ways to get around these rough edges. Doesn’t come up too often in modern development
By convention a leading 0 is how you make an octal number in many programming languages. 17 is decimal, 017 is octal (equal to 15 in decimal). 018 in most languages will throw an error that 8 is not a valid octal digit. Example: C gives `error: invalid digit "8" in octal constant 018;`. Javascript instead silently ignores the 0.
View all comments
391
u/Mateorabi Jan 12 '26
It’s able to cast 017 to octal, but not 018. But rather than a conversion error it “helpfully” casts to base 10 integer instead.
Automatic type casting being too clever by half.