JavaScript Elevation notes-------Fourth chapter variables, scope, and memory issues

Source: Internet
Author: User

first , the variables in JavaScript are divided into basic types and reference types.

A basic type is a simple piece of data that is stored in the stack memory, whereas a reference type refers to an object that is stored in the heap memory.

1. Parameter passing

The passing of all parameters in JavaScript is a value pass.

1.1 Delivery of basic data types (undefined, null,boolean,number,string)

1--->var money = 10;

2--->var t=function (money) {
Money = 5;
alert (money); 5
}
3--->t (money);

4--->alert (money); 10

The execution process ① the value of the initialization money in the global environment is 10; ② creates the execution environment of the function T, ③ executes the T function to copy the value of the variable of money in the global environment to the money function in the T function, the money in the body is changed to 5 and then executed ④ The money value in the global is still 10

1.2 Passing of the object (pass is the reference address of the object)

1--->var person = new Object ();
2--->

4--->alert (person.name); Zhangsan

The execution process ① the person in the global environment, the person refers to an empty object on the stack, and ② copies the object address value referenced by the person to student; ③ adds the student referenced object to the name attribute to Zhangsan④ Because student and person refer to the same object, the value is zhangsan!

Example diagram

JavaScript Elevation notes-------Fourth chapter variables, scope, and memory issues

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.