As mentioned before, a truthy value is a value that resolves to
true when type coerced.
If your value is anything other than these 7 values, it is truthy.
Checking for Truthy Values
If you're not sure if your value is truthy or not, an easy way to check if the value is truthy is to use the
! operator, then convert it back to the correct boolean value with the second
Here's how to check if a value is truthy:
const isTruthy = !!value;
Most values are truthy, with an exception of those 7 values above.
Thanks for reading!
- Getting Started with TypeScript
- How to Install Node on Windows, macOS and Linux
- Getting Started with Solid
- Managing PHP Dependencies with Composer
- How to deploy a .NET app using Docker
- Best Visual Studio Code Extensions for 2022
- How to deploy an Express app using Docker
- Using Puppeteer and Jest for End-to-End Testing
- How to Scrape the Web using Node.js and Puppeteer
- Build a Real-Time Chat App with Node, Express, and Socket.io
- Building a Real-Time Note-Taking App with Vue and Firebase