JS data type and judgment of data type

JS data types can help us manipulate variables better.
There are 8 data types
Number, String, Boolean, Null, undefined, object, symbol, bigInt
1 Undefind.: There is only one value, that is, undefind. When a variable is declared but not initialized, the value of this variable is undefind
2 Null: There is only one value, which is null. From a logical point of view, null is an empty object pointer. Therefore, using typeof to detect null will return "object".
3 Boolean.: There are two values: true and false.
4. Number: There are two identification methods: integer and floating point.
5 String.: String.
6 Object.: is a collection of data and functions. Including: Array, Function and Data
7 Symbol.: Its instance is the only value of the type that cannot be changed

Judgment of javaScript data type
1. typeof
returns a string, which is suitable for judging function objects and basic data types
2. instance of
obj instance of Object; obj on the left is an object, and Object on the right is a function object or function constructor, otherwise a TypeError is thrown . Instanceof is used to determine whether there is the prototype property of the right constructor on the prototype chain of the left object, that is, whether the specified object is an instance of a certain constructor.
. 3, constructor
all instances of objects are constructor property, attribute points constructor prototype object constructor function is located, that is point to create a constructor this example
. 4, Object.prototype.toString
Insert picture description here
. 5, Duck type (type ducks)
, such as whether an object is determined Is an array, you can see whether this object has length() and other methods

Guess you like

Origin blog.csdn.net/zxlong020/article/details/108327808
Recommended