JavaScript raw values and object reference instance analysis
This article mainly introduces the JavaScript original value and the object reference method, the example analyzes the JavaScript original value and the object reference function, the definition and the related technique, needs the friend to be possible to refer to under
The examples in this article describe JavaScript raw values and methods for object references. Share to everyone for your reference. The specific analysis is as follows:
In a word: The original value is immutable, and the object reference is mutable.
The original values in JS (Undefined, null, Boolean, numeric, and string) are essentially different from objects (including arrays and functions). The original value cannot be changed, and no method can change an original value; for strings, all the methods in the string appear to return a modified string, which actually returns a new string value:
?
1 2 3 |
var str= "Hello World"; S.touppercase (); S is still the same |
The comparison of the original values is a comparison of values: they want to wait only if their values are equal.
Objects differ from the original values, first they are mutable, and then the comparison of objects is not a comparison of values; objects are compared by reference: they want to wait only if they reference the same base object.
To compare 2 separate objects or arrays, you must compare their properties or elements as follows:
?