JavaScript Advanced Programming Notes (Chapter 4th variables, scopes, and memory issues)

Source: Internet
Author: User

1. Primitive type value undefined, Null, Boolean, number, and String

Copy process for base type values ( plot )

The base type value occupies a fixed amount of space in memory and is therefore stored in the stack memory;
Copying a base type value from one variable to another creates a copy of the value;

2. Reference type value

Variables in variable objects and objects stored in the heap ( plots )

The value of a reference type is an object that is stored in heap memory;

A variable that contains a reference type value actually contains not the object itself, but a pointer to that object;
Copying the value of a reference type from one variable to another is actually a pointer, so two variables end up pointing to the same object;

3. Pass parameters, pass by value, pass by reference

The parameters of all functions in ECMAScript are passed by value. In other words, copying the values from the outside of the function to the parameters inside the function is the same as copying the value from one variable to another.
the delivery of a primitive type value is like a copy of a primitive type variable, whereas a reference to a value of a type is the same as a copy of a reference type variable. There are a lot of developers who may be confused at this point,
Because access variables are both by value and by reference, parameters can only be passed by value

function Addten (num) {    + =ten    ; return num;} var count =; var result =////30

function setName (obj) {    = "Nicholas";} var New Object (); SetName (person); alert (person.name)     ; // "Nicholas"

function setName (obj) {    = "Nicholas";     New Object ();     = "Greg";} var New Object (); SetName (person); alert (person.name)     ; // "Nicholas"

JavaScript Advanced Programming Notes (Chapter 4th variables, scopes, and memory issues)

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.