javascript - Check for NaN, null and >=0 in one condition -


i have var a;

its value can nan, null , +ve/-ve number including 0.

i require condition filters out values of such >=0 values yield true in if condition.

what best possible way achieve this, not wish use 3 different conditions joined using ||

typeof x == "number" && x >= 0 

this works follows:

  • null -- typeof null == "object" first part of expression returns false
  • nan -- typeof nan == "number" nan not greater than, less or equal number including second part of expression returns false
  • number -- other number greater or equal 0 expression returns true

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -