javascript value types and reference types

value type

1. Value type: string/number/boolean/undefined;

2. Storage: data of value type, which stores the variables of the data itself;

3. Assignment: Directly copy one copy of the stored data for assignment, and the two copies of data are completely independent in memory. Modifying one of the data leaves the other unaffected.

4. Use in functions: Modifying formal parameters inside a function will not affect external variables.

reference type

1. Reference type: object;

2. Storage: data of reference type, the address of the data in the memory is stored, and the data is stored separately in the memory;

3. Assignment: Copy the address stored in the variable and store it separately, but the two variables share the same object. When one of the objects is modified, when another reference is accessed, the modified object will also be accessed.

4. Use in functions: Modifying the object inside the function will affect the variables outside.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324895388&siteId=291194637