As written in the JavaScript Advanced programming:
JS data types are divided into basic types and reference types.
So what is the basic data type?
For example, String,number,boolean are basic data types. In layman's words, they can save a value, but they cannot invoke a method on a saved value.
However, you can create a new instance of the base type by using the following code:
For example:
var numberobject = new number (10); The actual arguments for the new instance in parentheses
The book has introduced, the type of detection object can be divided into TypeOf and Instanceof method, then what difference do they have?
Conceptually, typeof is suitable for detecting basic data types. The instanceof is suitable for detecting reference types.
Here is an example:
var numberobject = new number (10);
var numbervalue = 10;
Alert (typeof Numberobject); Returns "Object"
Alert (typeof Numbervalue); Returns "Number"
Alert (numberobject instanceof number); Returns True
Alert (numbervalue instanceof number); Returns false
The above example shows that the data type value can be returned correctly when TypeOf is used to detect the base data type. However, if a reference type is detected, only object is returned.
However, when you use instanceof to detect a reference type value, you can return the correct boolean value.
Data types for JavaScript