1. Conversion between objects and basic types:
No matter when the object is not null, it is true in a Boolean environment.
For example;
New Boolean (false );
New number (0 );
New String ("");
New array ();
Although the internal value is false, the object value is true;
Object? Valueof ()? Tostring ()
In the date class, tostring () conversion is performed first.
2. operate a data value in JS:
Methods for operating data in any language;
JS is no exception. js has three important methods to operate a data value.
1) copy it. For example, assign it to a new variable.
2) pass it as a parameter to a function or method.
3) Compare the value with other values.
JS operates the values of these data in two ways: Pass the value and transfer the address.
You can see from the name that the data is operated by passing the value. During the assignment process, the actual values are copied and stored in a new variable. The copied value and the original value are two completely independent values. Therefore, if you change the copy value, the original value will not be affected. When the data size is compared, the data is usually compared in bytes.
From the perspective of the name, the address is transferred to operate the data. During the value assignment process, the actual value addresses (which can be referenced) are copied. They are not completely independent. Therefore, if you change the value through reference, the original value will also change. When comparing the size, it usually depends on whether they reference the same address for comparison.
Simple address transfer example:
VaR A = new date ();
Alert (A. getdate ());
VaR B =;
B. setdate (21 );
Alert (A. getdate () // Output 21
3. In general:
The basic data type is operated by passing values. (If you forget the basic data types, you can go back to them .)
The object data type is operated by transferring the address. (Such as arrays and functions)
Example:
<SCRIPT>
// Pass the value
A = 1;
B =;
B = 2;
Alert (a); // output 1
// address transfer
X = [1, 2];
Y = x; // only a reference of X is assigned to Y, not X itself. The array has been assigned a value in the statement. After executing the Code , there is still only one array object, but we have two references to him.
Y [0] = 2;
alert (X [0] + "|" + X [1]); // output 2 | 2
note the character string:
strings in JS are copied and transmitted through address transfer, while they are compared by passing values.
objects and arrays are passed by passing values, but the passed value is actually a reference, not the object itself.
conclusion:
transfer and comparison of data type replication
pass data by Numeric value
pass data by Boolean value
the value of a string is immutable and immutable
object address transfer address
unchangeable: in JS, there is no way to change the content of the string value.
for a string, it is of little significance to pass the value to the address.