DEV Community

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

Posted on

2 2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay