What are falsy values in JavaScript?

Often when checking if a value is undefined, null, NaN, 0, "" , and false, you might find yourself writing code like this:

    if(name !== undefined && name !== null && name !==""){
        do stuff
    }

Which is tedious and hard to read. We can solve this by using falsy values:

    if(!name){
        do stuff
    }

Check out this CodeSandbox - try changing the name variable to either undefined, null, NaN, 0, "" , or false, and see what happens:

This is part of the JavaScript bite-size series of posts. Check out the rest here!