Truthy-or-falsy

Hey guys, I can’t understand this solution:

const truthyOrFalsy = value => {

if (value) {

    return true

}

return false

}

When I dealt with this exercise, I came up with this code:

const truthyOrFalsy= (a) =>{

if ((a===’’ || a==="" || a===``) || (a=== false) ||(a===0)||(a===null)||(a===undefined)||(a===NaN)

) {

return false;

}else{

return true;

}

};

My question is why but putting the variable value is enough as a condition to find out if the value will be truthy or falsy. Why we don’t need to mention all of the case that it might be falsy as I did in my code. Thank you

if evaluates the truthiness of whatever is between the parenthesis. If the expression between the parenthesis is truthy, true is returned. Otherwise, the default return false is executed.

1 Like