Introduction to JavaScript Article 2 JS Type page 1/2

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.