typeof javascript
What value it has What the output shows you
when you write |console.log(typeof(variable);
Undefined: "undefined"
Null: "object"
Boolean: "boolean"
Number: "number"
String: "string"
Function object: "function"
E4X XML object: "xml"
E4X XMLList object: "xml"
NodeList "Nodelist [more data]"
HTMLCollection "HTMLCollection(1) [more data]"// get type of variable
var number = 1
var string = 'hello world'
var dict = {a: 1, b: 2, c: 3}
console.log(typeof number) // number
console.log(typeof string) // string
console.log(typeof dict) // object//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//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 Keywordconsole.log(typeof 'blubber');