1 What value it has What the output shows you
2 when you write |console.log(typeof(variable);
3Undefined: "undefined"
4Null: "object"
5Boolean: "boolean"
6Number: "number"
7String: "string"
8Function object: "function"
9E4X XML object: "xml"
10E4X XMLList object: "xml"
11NodeList "Nodelist [more data]"
12HTMLCollection "HTMLCollection(1) [more data]"
1// get type of variable
2
3var number = 1
4var string = 'hello world'
5var dict = {a: 1, b: 2, c: 3}
6
7console.log(typeof number) // number
8console.log(typeof string) // string
9console.log(typeof dict) // object
1//typeof() will return the type of value in its parameters.
2//some examples of types: undefined, NaN, number, string, object, array
3
4//example of a practical usage
5if (typeof(value) !== "undefined") {//also, make sure that the type name is a string
6 //execute code
7}
1console.log(typeof 93);
2// Output = "number"
3
4console.log(typeof 'Maximum');
5// Output = 'string'
6
7console.log(typeof false);
8// Output = "boolean"
9
10console.log(typeof anUndeclaredVariable);
11// Output = "undefined"
1var miFuncion = new Function("5+2")
2var forma = "redonda"
3var tamano = 1
4var hoy = new Date()
5
6
7typeof miFuncion === 'function'
8typeof forma === 'string'
9typeof tamano === 'number'
10typeof hoy === 'object'
11typeof noExiste === 'undefined'
12