What's the easiest way to check if a javascript variable is a number and greater than zero? -


this question has answer here:

i coded this:

        isnumbernotzero: function (num) {              // return false if num null, empty string or 0             if (num === null || typeof num === "undefined" || (typeof num === "string" && num.length === 0) || num == 0) {                 return false;             }             return true;         }, 

but there easier way this. code have not seem clean.

you doing lot of checking things not, when care if number greater zero.

just:

return typeof === "number" && > 0 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -