DEV Community

Discussion on: JavaScript Truthy and Falsy Values

Collapse
 
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:

gist.github.com/funfunction/42918a...

Collapse
 
osumgbachiamaka profile image
Osumgba Chiamaka

Nice example. Thanks for sharing.