@noelle idk `![]` being false seems expected to me, and `false + false` being 0 makes more sense than it being anything else, so the only part of this which i think might be objectionable is the fact that `[] + $` is a string

Follow

@noelle that’s definitely weird behaviour, but it falls out of the fact that strings and numbers are the only valid outputs of an addition operation, and having `[] + $` be a number is almost definitely worse

· · Web · 1 · 0 · 2

@Lady I figured you might respond. ;) Yeah, it's all expected behavior given the structure of the language, but the structure of the language makes me want to bop its designer with a rolled-up newspaper. :)

@noelle idk it makes more sense to me than the equivalent in Python :P

@noelle what makes this especially scary is that this is equivalent to "[]True"[2]

like, what??

@noelle i mean i get it but it is indicative of a fundamentally different understanding of []

in JS, [] is just a special kind of object, and all objects are truthy

Python doesn’t take the same “everything is an object™” approach so you wind up with more exceptional cases like that

@noelle which is why personally i don’t like Python (because i find the “everything is an object” approach to be much simpler to reason about than whatever it is Python does) but i understand how for other people, the incredibly ambiguous mess which is JavaScript would be bothersome lol

@noelle anyway i think the reason why javascript gets a weird reputation isn’t because it lets you do weird typecasting things but because it lets you do weird typecasting things in very very few characters 😝

@noelle “every operator should return a result without throwing an error” is definitely A Choice and they sure made it

@noelle (strictly speaking javascript operators can throw errors if .valueOf() or .toString() also throw errors or ultimately fail to produce primitives, but that’s not the case for any builtin thing i don’t think. maybe some of the newer ones? i’d have to check)

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.