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:
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:
function Equ_arrays (a,b) {
if (a.length!= b.lenght) return false;
for (Var i=0;i<a.length;i++)
if (A[i]!== b[i]) return false;
return true;
}
I hope this article will help you with your JavaScript programming.