Skip to content

TodayILearned - 2023-06-20

Posted on:June 20, 2023 at 06:48 AM

#TIL - Truthy vs. Falsy Values

These are two concepts that I felt like I knew but recently realized have been understanding very ‘vaguely.’ So let’s quickly do a TIL post on it.

Truthy

Falsy

Previously during coding, I made the mistake of believing that an empty array [] or object {} was falsy just like an empty string "". So when my intended conditional if statement was not running in the way I expected, I was totally baffled. Well, that’s because I thought an empty {} was falsy!

Now that I think about it, it makes sense that {} and [] are truthy when "" is considered falsy, since the former are non-primitive values and the latter is primitive. So even though the inner contents are empty, the said array and object still points to a reference or point in memory.

Super quick TIL today, but something I’ve been meaning to document on my blog.