How to write isNumber() in JavaScript?
This question already has an answer here:
function isNumber(val){
return typeof val==='number';
}
If I needed to write an isNumber
function for an API I would use:
function isNumber(val) {
return !isNaN(val);
}
...but I wouldn't bother writing an isNumber
function, as I'd just use isNaN
.
如果你想让"23"
成为一个数字,那么
function isNumber(val) {
return !isNaN(val);
}
链接地址: http://www.djcxy.com/p/26402.html
上一篇: 导致NaN故障的原因是什么?