Basic Data Types:Value access, which allows you to manipulate the actual value saved in the variable. Base type values refer to simple data segments.
There are five basic data types:Undefined、Null、String、Number、Boolean。
Citation Type:When copying a variable of an object, it is the reference of the object that is being manipulated, but when adding properties to the object, it is the actual object that is being manipulated. Reference type values are objects that may be composed of multiple values.
There are several types of citations:object, Array, RegExp, Date, Function, special basic wrapper types (String, Number, Boolean), and monolithic built-in objects (Global, Math).
For the difference between base type values and reference type values:
①Reference type values add properties and methods, while base type values cannot。
②When copying a variable value, the base type creates a new value on the variable object and copies it to the new variable. Since then,Any action of the two variables does not affect the other; The reference type is to copy a copy of the value stored in the variable object to the new variable, but the value of both variables points to an object stored in the heap, that is, they actually refer to the same object.Changing one variable affects the other。
Referencing type values, using an array as an example:
Pass parameters: Pass by value, copy the value outside the function to the parameter inside the function (a local variable), when the local variable is operated, the change of the local variable will be reflected outside the function, but this will not affect the value outside the function.
Of course, it can be difficult to understand when using objects:
Obviously, the parameters are passed by value, so why can the created p instance also get the name attribute added in setName()?
Because obj and p refer to the same object, obj will access the same object by reference, even if it is passed by value. Take a look at the example below to make it clear.
Rewrite the obj object inside the function, at this time the obj object is referencing a local object, and the outer p is still the original reference, so it will not change.
Types of assays:
typeof:确定变量是字符串、数值、布尔值还是undefined的最佳工具。
instanceof: Determine whether it is an object type.
|