Junior — Middle
Which values in JavaScript are considered falsy when converted to a boolean?
sobes.tech AI
Answer from AI
In JavaScript, the following values are considered falsy when converted to a boolean:
false0(zero)-0(negative zero)0n(BigInt zero)""(empty string)nullundefinedNaN
All other values are considered truthy.
Example:
if (!0) {
console.log('0 is falsy');
}
if (!"") {
console.log('Empty string is falsy');
}
if (!null) {
console.log('null is falsy');
}
This is important to consider when checking conditions and logical expressions.