JavaScript Advanced Programming (Third Edition) Chapter fourth variables, scope and memory issues

Source: Internet
Author: User
Tags getcolor

JavaScript variables can be used to hold two types of values: primitive type values and reference type values. Basic type values and reference type values have the following characteristics:

    • 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;
    • The value of a reference type is an object that is stored in heap memory;
    • A reference-type-worthy variable 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;
    • Determine which base type a value can use the TypeOf operator, and determine which reference type can use the instanceof operator.
4.1.3 Passing parameters
1<script type= "Text/javascript" >2         functionAddten (num) {3num + = 10;4             returnnum;5         }6         7         varCount = 208         varresult =Addten (count);9alert (count);// -Tenalert (result);//Ten One  A</script>
1     <script type= "Text/javascript" >2         function  setName (obj) {3             Obj.name = "Nicholas"; 4         }        5         var New Object (); 6         setName (person); 7         alert (person.name);    // "Nicholas" 8     </script>
4.2.2 does not have a block level scope
 <script type= "Text/javascript" > function   add (NUM1, num2) { var  sum = num1 + return   sum;   var  result = Add (10, 20); //     30  alert (sum); //  because sum is not a valid variable, it causes the error  </script> 
 1  <script type= "Text/javascript" > 2  function   add (NUM1, num2) { 3  sum = num1 + num2;  4   sum;  5   6  var  result = Add (10, 20); // 30                 7  alert (sum); // 30  8  </script> 
1     <script type= "Text/javascript" >2         var color = "Blue"; 3         4         function GetColor () {5             return color; 6         }7         8         alert (GetColor ());  // "Blue"    9     </script>
1<script type= "Text/javascript" >2         varcolor = "Blue";3         4         functionGetColor () {5             varcolor = "Red";6             returncolor;7         }8         9Alert (GetColor ());//"Red"Ten</script>

JavaScript Advanced Programming (Third Edition) Chapter fourth variables, scope 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.