JS basic Syntax value type (data type) (variable type)

Source: Internet
Author: User

I. Non-changing raw values (stack data) (five)

Number, String (string), Boolean value (Boolean), Undefined,null

The undefined is undefined meaning, and null is empty meaning, the difference between them is that null has value, but this value is null, and undefined is undefined, there is no value at all. Null is generally used as a placeholder.

var a = 4; var b == ten; Console.log (b); // 4 // The original value is put a value A in another value B inside, changed the first value A, the second value B is unchanged

Two. Reference value (heap data)

Arrays (array), objects (object), Functions (function)

Note: The memory will be re-applied as long as the variable is assigned

1.

var arr = [1, 2]; var arr1=Arr;arr.push (3)//[1, 2, 3]//  When referencing a value, place the first value inside the second value, change the first value, and the second value changes
The reference value is the address of the heap in the stack memory, the copy is the address, so changed arr, actually changed the address that arr points to the contents of the store, and Arr and arr1 point to the same address, so arr1 also changed

Address

Variable

Store value

0x0001

Arr

[All ] [<--arr.push] (3)

0x0002

Arr1

0x0001

2.

 var  arr = [1,2 var  arr1 = Arr;arr  = [1,3];console.log (arr1);  //    [1,2];  // arr = [1,3] actually built another address within the heap, and arr points to the new address, The arr1 still points to the original address, so the ARR1 value is unchanged  

address

variable

storage value

0x0001

a rr  

[1,2]   

0x0002

arr1

0x0001

0x0003

arr

[1,3]

3.

var a = {N:1}; var b = A;A.N= a={m:1};console.log (a); // {m:1}Console.log (b); // {N:{m:1}}

1.var a = {N:1}, request two addresses in memory, storing A and n respectively;

2.var B = A; Apply for an address that holds B, and the value points to the address of A;

3.a.n= a={m:1};

(1) (the variable is assigned, so to re-request memory) first requested memory address N (0x0004) and A (0x0005), because the N value occupies a new memory, so 0x0001 storage value from n:0x0002 to n:0x0004;

(2) Assign value; a={m:1}, Request M address (0x0006),

Therefore: A: {m:0x0006}--->{m:1}

B: {0x0001}--->{n:0x0004}---->{n:0x0005}---->{n:{m:0x0006}}--->{n:{m:1}}

Address

Variable

Store value

0x0001

    &NBSP;A&NBSP; &NBSP; (1)

n:0x0002 &NBSP;  n:0x0004 Span style= "font-family: Song body; font-size:10.5pt; Color: #ff0000 "> ---(1)

0x0002

- N (1)

1

0x0003

B

0x0001

0x0004

n (1)

0x0005

0x0005

A (1)

M:0X0006 (2)

0x0006

m (2)

1 (2)

JS basic Syntax value type (data type) (variable type)

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.