Comment by echoangle
You don‘t think being able to check the truthiness of strings is a useful thing?
You don‘t think being able to check the truthiness of strings is a useful thing?
What does "useful" mean here? Useful the way it'd be useful if butter knives could also cut trees down more easily or if hats were also televisions - ie more uses = more useful?
Programming languages aren't for the machine, they're for humans, and humans make mistakes so we need to design the language with that in mind. "Truthiness" is a footgun, it increases the chance you'll write something you did not mean without even realising.
A little bit of truthiness seems like a good idea at first. You decide to treat empty strings and undefined as falsy and it feels good, so you go ahead and start treating zero as falsy too.
And then all of a sudden code that is expecting to get an array or undefined gets handed a zero or an empty string because someone called it with
Or And that’s how you end up with a zero showing up on a webpage instead of a list of to-do items when the list is empty.