check data type in javascript

JavaScript
function doSomething(x) {
  if(typeof(x) === 'string') {
    alert('x is a string')
  } else if(typeof(x) === 'number') {
    alert('x is a number')
  }
}> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"

if(typeof bar === 'number') {
   //whatever
}typeof("string"); //string
typeof(123); //number//typeof() will return the type of value in it's parameters.
//some examples of types: undefined, NaN, number, string, object, array

//example of a practical usage
if (typeof(value) !== "undefined") {//asuming value is already set
  	//execute code
}console.log(typeof 42);typeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword
Source

Also in JavaScript: