Advertisements
how we can falsy value from a returned function.
I have a function block that from the returned value we make decisions and with an undefined value or NaN value we should have a false value how can I reach that?
for example
console.log(Boolean(() =\>{return NaN})
is true
>Solution :
Function objects are always true
when converted to boolean. You want to convert the return value of the function to a boolean, so you need to call the function.
console.log(Boolean((() => {return NaN})()));
// or more explicitly:
const f = () => NaN;
console.log(Boolean(f())); // equivalent to !!f()