Skip to content

re: I'm Javascript. And I'm done taking your shit. VIEW POST

re: My only complaint with JS, isn't even to do with JS. As I originally posted in the comment on this, my complaint is the people that see JS as a pa...

I'm still very curious about what you meant with undefined Booleans, though. 😅

Again, note the capitalisation.

Consider the following JS:

var someBool;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }
someBool = true;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }
someBool = false;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }

Now, consider that coming from a strictly typed background, the above code shows a boolean variable (not a Boolean) in 3 different states, when the very intent of booleans is a binary state.

If one is not aware of that particular nuance, it leads to frustration & wasted time. Of course, you could make the argument that if you don't understand the nuances of a language, why are you writing in it... but where's the fine line in "sufficient knowledge" there? And why would a Project Manager looking at a deadline care if you know enough or not?

I love the fact that the two people to want to discuss this point, read "boolean" as "Boolean" :D

The only data type where the variable name and its value are correlated are symbols (or atoms, or literals depending on what the language you use calls them).

In the example you give, var someBool is no more a boolean than var cow is a bovine animal in any dynamic or statically typed language I can think of at the moment.

What the if statements are evaluating is whether or not the value type is undefined which is only very thinly related to booleans.

For reference:


Well, booleans can only be true or false. however, a variable named in a way that makes it seem like it should reference a boolean can, of course, be uninitialized if you allow uninitialized declarations. And I guess that's the thing; javascript by default allows you to declare uninitialized vars.

So; yes - javascript is useless at being java, c#, or any other strongly typed language, in the same way, those languages are useless at being javascript. But that's not really a fair comparison as they have traits not applicable to the other.

Nor did I say it was a fair comparison, nor did I even really say it's an issue (of any size).

But surely, you can see that - as was the intent of my reply to the other person, from an OO/strictly typed background, JavaScript is indeed very easy to get wrong. That's no different to any other language if we only have surface knowledge in them.

In other languages, such as Java, the primitive boolean datatype exists, and null exists, but a boolean can never be null, it is either true or false. Again, that's because of strict typing, and strictly typed languages simply make more sense in my head.

Does that stop me using JS? No... but you were curious, so I expanded on my comment.

I'm aware of how to use JavaScript, and do so more times than I'd like, so no need for the documents, or the defence of JS, but thanks.

There's no way to respond to that statement productively.

code of conduct - report abuse