Truthy/Falsy
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
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:
1, 2, 42, -13."hello", "a", "foo".Falsy values are:
0."".null.[].{}.The process of automatically converting values for some expressions is called "type coercion". It's said that the value is coerced into a boolean.
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).
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.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…