use typeof();
example
example:
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
So you can do:
if(typeof bar === 'string') {
//whatever
}
Keep in mind that, typeof is only good for returning the "primitive" types, number, boolean, object, string. You can also use instanceof to test if an object is of a specific type.
function MyObj(prop) {
this.prop = prop;
}
var obj = new MyObj(10);
console.log(obj instanceof MyObj && obj instanceof Object); // outputs true