F**king JavaScript Types

This post is more of a rant on JavaScript than anything.

For the first around 5 years of my developer life, I never touched JS. I first learned Java and wanted to distance myself from it as far as possible as I assumed they were similar.

Well, they are. They’re both f*king stupid. In the same ways, no, but still stupid. In C#, if I wanted to check if something was a valid number, I’d simply use myvar as int and check for null. If I compare that variable to another, it’ll do a type check. But instead, in JS, I have to do hacky BS like if (!(myvar <= 0)) to check if something is not only greater than 0, but also not undefined and of the same type. Why can’t I just do myvar >= 0? Why can’t it just assume the type from the comparison? Why can’t JavaScript just have f**king types? “Then it’s not a scripting language!” or “everything is an object!”. No. This isn’t Ruby. Types were introduced into ES2015 for a reason. If I’m comparing “foo” and 5, I shouldn’t get false, I should get new Error("Cannot implicitly convert string to number").

Really. I get how useful undefined returning falsey is. I’m guilty of it, even though I should be doing explicit checks of var == undefined. But maybe we should only have that. We shouldn’t be worried about if the variable we’re checking is reference undefined or value undefined, or I’m gonna pull my hair out some more.

 
2
Kudos
 
2
Kudos

Now read this

typeof JavaScript != typeof Java

Recently, I’ve been re-working an old project in Java. For those that are familiar with the PC Minecraft community, a couple years ago a plugin enabled server called “Bukkit” existed. It was handy, it was modular, and it was good. There... Continue →