1console.log(typeof "how are you?")
2"string"
3console.log(typeof false) / console.log(typeof true)
4"boolean"
5console.log(typeof 100)
6"number"
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}
1typeof("iAmAString");//This should return 'string'
2//NO camelCase, as it is a JS Keyword
1var trueTypeOf = function (obj) {
2 return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
3};
4
5// Returns "array"
6trueTypeOf([]);
7
8// Returns "date"
9trueTypeOf(new Date());
10