I. What is a type
JavaScript does not have a class concept. However, there are still two types: primitive type and application type.
The original type is saved as a simple data value, and the reference type is saved as an object, essentially pointing to the memory location
The reference. That is, the original value is stored directly inside the object, and the reference value is saved as a pointer to the
object, which points to where the actual object is stored in memory.
Two. Original type
2.1 JavaScript in 5 original type: boolean,number,string,null,undefined
The original type variable directly saves the original value (not a pointer) when you assign the original value to a variable
, the value is copied into the variable.
1 var color1 = 'red; 2 var // Copy the value of Color1 to a variable color2 3 Color1 = ' Blue '; 4 // ' Blue ' 5 // ' Red '
2.2 Identifying the original type
The best way to identify the original type is to use the TypeOf operator.
2.3 Original method
Although strings, numbers, and booleans are primitive types, they have methods (underfined and null are not)
1Console.log (typeof' Hello ');//' String '2Console.log (typeof10);//' number '3Console.log (typeof5.1);//' number '4Console.log (typeof true);//' Boolean '5Console.log (typeofunderfined);//' underfined '6Console.log (typeof NULL);//' object ' to determine if a value is null, direct and NULL comparisons7Console.log (NULL= = underfined);//' true ';8Console.log (NULL= = = underfined);//' false ';
Three. Reference types
3.1 Creating objects
1 var New Object (); 2 var = Create. Object (); 3 var o3 = {};
3.2 Object reference dismissed
3.3 Adding a Delete property
3.4 Instantiation of built-in objects
1) array//array type, ordinal list of a set of values indexed by numbers
2) Date/date and time type
3) Error//Run-time type
4) function//functions type
5) Object//Universal Object type
6) REGEXP//Regular expression type
3.5 object and Array literal form
1 var o = {2 naem: ' Hello ',3 age:14 }; 5 var arr = [n/a];
3.6 literal form of function
1 function Ref (value) {2 return value; 3 }; 4 var New Function (' value ', ' return value; ')
3.7 Regular expression literal form
1 var numbers =/\d+/g; 2 var New REGEXP ("\\d+", "G");
3.8 Access Properties
1 var arr = []; 2 Arr.push (123); 3 var arr2 = []; 4 arr2["Push"] (123);
3.9 Identifying reference types
Functions can use typeof and arrays and objects use the instanceof operator
1 var arr = []; 2 var o = {}; 3 function f () {}; 4 instanceof // true 5 instanceof // true 6 instanceof // true
3.10 Identification array using Array.isarray ();
1 var arr = []; 2 // true
four. Original package Type
There are 3 types of original package type (Number,string,boolean)
1 var name = ' Nicholas '; 2 var New String (name); 3 Temp.last = ' Zakas '; 4 NULL ; 5 // underfined
Temporary objects are created only when values are read
01.JavaScript Object-oriented essentials--primitive types and reference types