A. JS has 5 basic types and 1 object types (reference types)
5 Basic types: Number\string\null\undefined\boolean
1 Types of objects: Function, Array, Date
Two. Type conversion
Skillfully type conversion with +/-
Three. = = and = = =
= =:
1. For the base type, try the type conversion and then compare!
2. For reference types, comparisons are being directed to the same object (address comparison)
= = =:
1. Return FALSE for different types
2. The same type:
Null===null
undefined===undefined
Four. Special value: NaN
Nan:not a Nnmber
This value was introduced in the original case of "returning a number but not returning a number". This situation (such as "I") in other languages will be an error, but in JS will not error, but the return value Nan. So that the process can continue to execute.
The particularity of Nan: It is not equal to any type of comparison, including its own! So to determine whether a value is Nan, you must use the global function isNaN above the Window Object!
1. For the base type, try the conversion of number type before judging
2. For an object type, the first call to its valueof attempts to convert and then judge
var o = { valueof:function () { return "$"; } } IsNaN (o);//false
Five. Packaging objects
Some of the basic types have corresponding wrapper objects:
' str ': Wrapper object String
123: Wrapper Object number
True: Wrap Object Bealon Objects
When the base type tries to use it as an object (for example, by using its Length property to increase its properties), JS converts it to the object of the wrapper type (temporary object), but when such a visit is completed, JS destroys the temporary object!
Six. Type detection
1.typeOf: Basic type, function type
2.instanceof: operator based on the prototype chain
Obj instanceof object determines if obj has a Object.prototype object on the prototype chain (that is, if obj is an instance of object)
3.object.prototype.tostring
The previous two types of detection methods are more commonly used!
JavaScript data types