typeof("string"); //string typeof(123); //number
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 operando
var x = 12345; console.log(typeof x) // number x = 'string'; console.log(typeof x) // string x = { key: 'value' }; console.log(typeof x) // object