Using the detected data type typeof

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

  1. "Number": is the numerical value detected;
  2. "Boolean": the detected value is a Boolean type, true or false;
  3. "String": a string value detected;
  4. "Object": value of an object is detected, an array, or null;
  5. "Function": value detected is a function;
  6. "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

Guess you like

Origin blog.csdn.net/abcdef12030/article/details/91548335