I like to use the !! in Javascript to ensure that a variable is set and that no error will be thrown.
However today I have a variable with 0 value that is valid for me. I need to ensure that it is not NaN nor undefined, is there really no short way to do it without the boring if (variable !== NaN && variable !== undefined?
If that may help, I am using angular.
Thx.
if (variable) { }variable !== NaNwill always be true, becauseNaN != NaN. To properly check forNaNyou need to useisNaN().if (variable != null && !isNaN(variable)). As far as I know, this will be the shortest way to implement your logic.