Skip to content
refractalize edited this page Mar 21, 2012 · 9 revisions

Falseyness

JavaScript, it is well known, has a strange notion of falseyness. So when I was designing PogoScript I wondered if there would be an appetite for it being less strange.

In particular, I thought Ruby had the nicest semantics for falseyness, that is, only nil and false itself were false and nothing else. This follows what I thought were Lisp semantics, but I would be corrected.

In fact every language has a different notion of falseyness, which surprised me because having written plenty of code in plenty of languages, I thought I would have noticed this.

I then looked into a number of other languages and found some surprising results. What I was looking for were values that would not pass as a true condition to an if statement/expression.

Lisp: nil and the empty list (), which are actually the same thing in Lisp. Lisp doesn't have a "false".

JavaScript: empty string "", 0, null, undefined and false.

Ruby: false and nil.

Python: empty string "", 0, None and empty string [].

C/C++: NULL and FALSE which are really just macros for 0.

C# and Java: false. Not even null is allowed in an if statement.

Go: false. Same as C# and Java.

So given that all languages are a bit weird, and that PogoScript is running on JavaScript I think I'll stick to JavaScript semantics.

Clone this wiki locally