我编码为:
isNumberNotZero: function (num) {
// Return false if num is null, an empty string or zero
if (num === null || typeof num === "undefined" || (typeof num === "string" && num.length === 0) || num == 0) {
return false;
}
return true;
},
但是有没有更简单的方法可以做到这一点。我的代码似乎不太干净。
当您仅检查它是否是大于零的数字时,您会做很多检查,以检查不是的情况。
只是:
return typeof a === "number" && a > 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句