Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Find a js code, and use JS to judge whether the var type obtained is string type or int type.
Find a js code, and use JS to judge whether the var type obtained is string type or int type.
First of all, there is no concept of int in js. What you want to judge is character type and numerical type.

Suppose the variable is not.

Code:

if(object . prototype . tostring . call(a)= '[object String]'){

//a is a character type.

}

The above code can determine whether A is a string type or a string object.

If (object.prototype.tostring.call (a) =' [object number]') {

//a is a numeric type.

}

The above code can determine whether A is a numeric type or a numeric object.