Q:

typeof in js

//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
}
8
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
1
var x = 12345; 
console.log(typeof x) // number
x = 'string'; 
console.log(typeof x) // string
x = { key: 'value' };
console.log(typeof x) // object
0
typeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword
4
console.log(typeof 'blubber');
3
//retourne le type de la variable

let number = 1;
let string = "bonjour";
let bool = true;
let dict = { a: 1, b:2 };

console.log(typeof(number));//renvoie Number
console.log(typeof(string));//renvoie String
console.log(typeof(bool));//renvoie Boolean
console.log(typeof(dict));//renvoie Object

//cas spécial

console.log(typeof(NaN));//NaN = Not A Number renvoie Number
0

New to Communities?

Join the community