DEV Community

Cover image for Clojure 101 / logical true or false
icncsx
icncsx

Posted on

Clojure 101 / logical true or false

A falsy value is a value that is considered false when encountered in a boolean context (i.e. if...else).

In JavaScript, there are 8 types of falsy values. This is from MDN.

Alt Text

In Clojure, it's dead simple. Everything except false and nil is true in the boolean context.

(if nil
  "NIL IS TRUTHY"
  "NIL IS FALSY")

;; "NIL IS FALSY"
Enter fullscreen mode Exit fullscreen mode

Isn't that nice? No more guess work :)

Warmly,
DH

Top comments (0)