JavaScript Port Of PHP’s is_int() And is_integer()

The is_int() func­tion finds whether the type of the given vari­able is integer. The two things we need to do is check that the variable’s con­structor is Number and that, if we round it up, the num­ber 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.

    What do you think? Leave a comment...