将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

 

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-10-12
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-09-13
  • 2021-11-17
  • 2022-12-23
  • 2021-07-11
  • 2022-01-10
相关资源
相似解决方案