typeof detection data type
We generally use the detection data type typeof (typeof X-acting with typeof (X-) is the same, the result is detected by the data type)
There are six types of data returned
- "Number": is the numerical value detected;
- "Boolean": the detected value is a Boolean type, true or false;
- "String": a string value detected;
- "Object": value of an object is detected, an array, or null;
- "Function": value detected is a function;
- "Undefined": variable detected only a declaration, but the assignment;
The following are examples of several types of detection data
detection result is "object":
console.log(typeof null)//"object"
var arr=[1,2,3];
console.log(typeof arr)//"object"
var obj={"a":"1"};
console.log(typeof obj)//"object"
Test results for "function":
function getType(){
console.log("笑哈哈");
}
console.log(typeof getType);//"function"
console.log(typeof(getType));//"function"
- Operands typeof operator may be variable, it may be a literal value. Note that, typeof is an operator rather than a function, and therefore although the example in parentheses may be used, but is not required.
- Technically speaking, the object function in ECMAScript is not a data type. However, the function does have some special properties, functions and thus to distinguish between other objects by typeof operator is necessary