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

```
use JavaScript built in `typeof` function

```
var s = "string",
    n = 1; // number

if(typeof s == 'string'){
  //do stuff for string
}

if(typeof n == 'number'){
  //do stuff for number
}

```