DEV Community


Discussion on: JavaScript Truthy and Falsy Values

functional_js profile image
Functional Javascript • Edited

Excellent analysis Osumgba.

Here's an example showing what's truthy and what's falsy in JavaScript:

//truthy values
const aT = [true, {}, [], 25, 12n, "true", "false", new Date(),
  Infinity, Boolean(true), new Boolean(false), n => n

//falsy values
const aF = [false, null, undefined, NaN, 0, -0, 0n, "", Boolean(false)];

logForeachParam(v => !!v, aT);
logForeachParam(v => !!v, aF);

after running it:

javascript truthy and falsy

logForeachParam Source Code:

osumgbachiamaka profile image
Osumgba Chiamaka Author

Nice example. Thanks for sharing.

Forem Open with the Forem app