Is there an elegant way to check if variable is NOT falsy but in case of 0 it passes. The issue with this way of verifying if(var !== undefined && var !== null) is that it’s long and doesn’t cover all cases like undecalred or NaN. I’m also using typescript and declare it as optional number. Answer You can do
Tag: truthy
trouble with truthy/falsey
A quick intro, I am a total noob learning JS and feel that it’s going well, however I am doing a simple exercise right now and I’m hung up on something. I have learned that: a falsey value is a value that is considered false when encountered in a boolean context ex: false, 0, -0, 0n, “”, null, undefined, NaN