programming-examples/js/Math/Check whether a value is an integer or not .js
2019-11-15 12:59:38 +01:00

14 lines
358 B
JavaScript

function is_Int(num) {
if (typeof num !== 'number')
return false;
return !isNaN(num) &&
parseInt(Number(num)) == num &&
!isNaN(parseInt(num, 10));
}
console.log(is_Int(23));
console.log(is_Int(4e2));
console.log(is_Int(NaN));
console.log(is_Int(23.75));
console.log(is_Int(-23));