programming-examples/js/Math/Find out if a number is a natural or not.js
2019-11-15 12:59:38 +01:00

10 lines
343 B
JavaScript

function is_Natural(n)
{
if (typeof n !== 'number')
return 'Not a number';
return (n >= 0.0) && (Math.floor(n) === n) && n !== Infinity;
}
console.log(is_Natural(-15));
console.log(is_Natural(1));<br>console.log(is_Natural(10.22));
console.log(is_Natural(10/0));