在一个条件中检查NaN,null和> = 0 [英] Check for NaN, null and >=0 in one condition

查看:79
本文介绍了在一个条件中检查NaN,null和> = 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个var a;

I have a var a;

它的值可以是 NaN,null和任何+ ve / -ve数,包括0。

我需要一个过滤掉a的所有值的条件,只有> = 0的值会在if条件下产生一个真值。

I require a condition which filters out all the values of a such that only >=0 values yield a true in if condition.

实现这一目标的最佳方式是什么,我不希望使用 ||

What is the best possible way to achieve this, I do not wish to use 3 different conditions joined using ||

推荐答案

哦......但我确实找到了ans ..
它很简单。

Ohk ...But i actually found the ans .. it is so Simple .

parseInt(null)= NaN。

parseInt(null) = NaN.

所以 if(parseInt(a)> = 0){} 会做... Yayyee

So if(parseInt(a)>=0){} would do ...Yayyee

这篇关于在一个条件中检查NaN,null和> = 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆