Skip to content

Instantly share code, notes, and snippets.

@cohei
Last active July 13, 2016 13:14
Show Gist options
  • Save cohei/b693eff9878658dbaf05 to your computer and use it in GitHub Desktop.
Save cohei/b693eff9878658dbaf05 to your computer and use it in GitHub Desktop.
List of Truthies and Falseys

Truthies and falseys are defined here as things which can be placed at the condition part of if statement.

C#

https://msdn.microsoft.com/library/system.boolean.aspx

// `bool` keyword is an alias of `System.Boolean`.
bool truthy = true;
Boolean truthy2 = true;

bool falsy = false;
Boolean falsy2 = false;

CoffeeScript

http://coffeescript.org/#conditionals

# same as JavaScript
truthies = [true, 1, 'string', new Object()]

falseys = [false, null, undefined, +0, -0, NaN, '']

Groovy

http://groovy.codehaus.org/Groovy+Truth

truthies = [true, 1, [false], "false"]

falseys = [false, 0, [], "", null]

Haskell

https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-320003.6

truthy :: Bool
truthy = True

falsey :: Bool
falsey = False

Java

boolean truthy = true;
Boolean truthy2 = true;

boolean falsy = false;
Boolean falsy2 = false;

JavaScript

http://www.ecma-international.org/ecma-262/5.1/#sec-9.2

var truthies = [true, 1, 'string', new Object(), new String('')];

var falseys = [false, null, undefined, +0, -0, NaN, ''];

OCaml

let truthy : bool = true ;;

let falsey : bool = false ;;

PureScript

truthy = true :: Boolean

falsey = false :: Boolean

Ruby

http://docs.ruby-lang.org/en/2.1.0/syntax/literals_rdoc.html#label-Booleans+and+nil

truthies = [true, 0, "", [], Object.new] # and any other objects except for nil, false

falseys = [false, nil]

Scala

val truthy: Boolean = true

val falsey: Boolean = false

Scheme

(define truthies '(#t 1 (1 2) ())) ; and anything except #f

(define falsy #f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment