Truthy/Falsy

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Truthy/Falsy

The keywords while and if only compare booleans. Any while or if statement receives an expression that evaluates to one of two values: true or false.

Most values in most (dynamic) programming languages can be coerced into true or false.

We call these values "truthy" and "falsy". If a value is truthy, it is considered true in a boolean context. If a value is falsy, it is considered false.

Truthy values are:

Falsy values are:

The process of automatically converting values for some expressions is called "type coercion". It's said that the value is coerced into a boolean.

Examples

The three snippets below are all equivalent. They all print "Words list is not empty." if the array words_list is not empty. The array is ["hello", "world"] in all cases, so the line appears in all cases.

In the first, we explicitly compare the size of the array to 0:

var words_list := ["hello", "world"]
if words_list.size() > 0:
	print("Words list is not empty.")

In the second, we use the implicit coercion of the size of the array to a boolean:

var words_list := ["hello", "world"]
if words_list.size():
	print("Words list is not empty.")

In the third, we use the implicit coercion of a non-empty array to a boolean:

var words_list := ["hello", "world"]
if words_list:
	print("Words list is not empty.")

Each example reaches the same result through different mechanisms.

These implicit conversions can be tricky, so we recommend to always be explicit (see the warning at the bottom of the type coercion article).

Become an Indie Gamedev with GDQuest!

Don't stop here. Step-by-step tutorials are fun but they only take you so far.

Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!