JavaScript Getting Started learning the second JS type 1th/2 Page _ Basics

Source: Internet
Author: User
Tags getdate
1, the conversion between the object and the basic type:
The object is not empty at any time, and is true in a Boolean environment.
As
New Boolean (FALSE);
New number (0);
New String ("");
New Array ();
Although the internal value is false, the value of the object is true;
Object? ValueOf ()? ToString ()
Where the date class is to perform the ToString () conversion first.

To manipulate a data value in 2,JS:
Any language has its own method of manipulating data;
JS is no exception, JS has 3 important ways to manipulate 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) can be compared to other values of size.

JS operates the value of the data by passing the value and sending the address 2 ways.
From the name can be seen, the value is passed by passing values to manipulate the data. In the process of assignment, the actual value is copied and stored in a new variable. The value of the copy and the original value are 2 completely independent values. So if you change the value of the copy, it doesn't affect the original value. When you compare the size, you usually do a byte comparison.
An address is a name that is used to manipulate data by passing addresses. In the process of assigning values, the address of the actual value (which can be referred to as a reference) is copied, and they are not completely independent, so if you change the value by reference, the original value will change. When comparing sizes, it is usually to see if they refer to the same address for comparison.
Simple example of an address:
var a = new Date ();
Alert (A.getdate ());
var B = A;
B.setdate (21);
Alert (A.getdate ())//Output 21

3, in general:
The base data type is manipulated by passing values. (If you forget what the basic data type is, you can look back.) )
The object data type is manipulated by an address. (such as arrays and functions)
Example:
<script>
Pass Value
A=1;
B=a;
b=2;
alert (a); Output 1

Address
x=[1,2];
Y=x; The y is assigned a reference to x, not the x itself. The array has been assigned to the statement, and after executing this code, there is still only one array object, but we have 2 references to him.
y[0]=2;
Alert (x[0] + "|  "+x[1]);  Output 2 | 2
</script>
Where we have to pay attention to strings:
In JS, strings are copied and passed through the address, and they are compared by passing values.
Objects and arrays are passed by value, except that the value passed is actually a reference, not the object itself.
Summarize:
Type replication Delivery comparison
Digital Transfer Value Transfer value
Boolean Transfer Value Transfer value
Variable immutable values of strings
Object-to-address and address-to-pass
Immutable: In JS, there is no way to change the contents of a string value.
For a string, it doesn't make much sense to pass a value or to pass the address.
Current 1/2 page 12 Next read the full text
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.