typeof("string"); //string typeof(123); //number
> typeof "foo" "string" > typeof true "boolean" > typeof 42 "number" if(typeof bar === 'number') { //whatever }
if (typeof i != "number") { console.log('This is not 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 }
typeof("iAmAString");//This should return 'string' //NO camelCase, as it is a JS Keyword
console.log(typeof "how are you?") "string" console.log(typeof false) / console.log(typeof true) "boolean" console.log(typeof 100) "number"
console.log(typeof 93); // Output = "number" console.log(typeof 'Maximum'); // Output = 'string' console.log(typeof false); // Output = "boolean" console.log(typeof anUndeclaredVariable); // Output = "undefined"
typeof operando
> typeof "foo" "string" > typeof true "boolean" > typeof 42 "number"
var x = "Hello World"; typeof x; // "string"