Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why NaN that returned from a function is not falsy value?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading