What are truthy and falsy values in JavaScript?
Learn which values evaluate to true or false in JavaScript conditionals.
Advertisement
Question
What are truthy and falsy values in JavaScript?
Answer
Every value in JavaScript is either truthy or falsy when evaluated in a Boolean context.
Falsy values:
false, 0, -0, "", null, undefined, NaN
Everything else is truthy.
if ('') console.log('Truthy');
else console.log('Falsy'); // Falsy
Truthy values are all non-falsy ones, like "hello", 42, {}, and [].
Real-World Example
Falsy values are often used in condition checks:
const user = '';
if (!user) {
console.log('No user logged in');
}
Quick Practice
Write a function that checks if a value is truthy or falsy using a simple conditional.
Summary
Knowing what’s truthy or falsy helps you write cleaner, bug-free conditionals.
Is an empty array [] truthy or falsy?
It’s truthy, even though it’s empty — all objects are truthy in JavaScript.
Advertisement
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.
Advertisement