实现函数 isInteger(x) 来判断 x 是否是整数

将x转换为十进制整数,判断是否和自身相等即可:

1     function isInteger(x){
2         return parseInt(x, 10) === x;
3     }
4     console.log('1.2 is an integer?'+isInteger(1.2)); // false
5     console.log('35 is an integer?'+isInteger(35)); // true
原文地址:https://www.cnblogs.com/xiayu25/p/6270349.html