Question: > 
> **Possible Duplicate:**  
> 
> [Finding Variable Type in JavaScript](https://stackoverflow.com/questions/4456336/finding-variable-type-in-javascript) 
> 
> 
> 

How can I test if a value is a string or an int? Something like...

X = ?

if X is an Int {}

if X is a String {}

Thanks!

Answer: 
You can use the [typeof](https://developer.mozilla.org/en/JavaScript/Reference/Operators/Special/typeof) operator:

```
var x = 1;
console.log(typeof x);
x = 'asdf';
console.log(typeof x);

```

Prints:

```
number
string

```
Others have already talked about the `typeof` operator, and use of `Object.prototype.toString`, but if you want to specifically test for an int as compared to any sort of number then you can do some variation of this:

```
function isInt(n) {
   return typeof n === "number" && n === Math.floor(n);
}

```

(Insert all the `Object.prototype.toString` stuff if desired.)