Tip 17 Shorten Conditionals with Falsy Values

In this tip, you’ll learn how to use falsy and truthy values to check for information from different types.

Can you remember the first line of code you ever wrote? I can’t, but I wouldn’t be surprised if it was some sort of conditional. Responding one way to some information and a different way to other information is about as basic as programming can get.

I still write a lot of conditionals every day, and I bet you do, too. Fortunately, JavaScript, along with many other languages, gives you many tools for checking information and reassigning or standardizing information very quickly with minimal code.

The secret to being able to check values quickly is to understand the subtle difference ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.