The is_int() function finds whether the type of the given variable is integer. The two things we need to do is check that the variable’s constructor is Number and that, if we round it up, the number will still be the same.
function is_int(variable)
{
return variable.constructor === Number && Math.round(variable, 0) === variable;
}
Of course, is_integer() is just an alias so it’d be silly to not include it:
var is_integer = is_int;
Comments
No responses have been made so far. Add your comments.