Home>

In a word:the original value is immutable,Object references are mutable.

Primitive values ​​(undefined, null, boolean, numbers, and strings) in js are essentially different from objects (including arrays and functions).The original value is immutable.No method can change a primitive value;For strings,All methods in the string appear to return a modified string,What is actually returned is a new string value:


var str="hello world";
s.touppercase ();
s;// still unchanged

The comparison of primitive values ​​is a comparison of values:they only want to wait until their values ​​are equal.

The object is different from the original value,First they are mutable;Second, the comparison of objects is not the comparison of values;Object comparisons are all reference comparisons:if and only if they refer to the same base object,They just want to wait.

If i want to compare 2 separate objects or arrays,Must compare their attributes 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;
}
  • Previous 2 ways to monitor missed calls in Android
  • Next C ++ image hijacking backdoor instance analysis
  • Trends