JavaScript building blocks (i) variables, values, and objects

Source: Internet
Author: User

JavaScript variables, values, and object descriptions

The understanding of variables, values, and objects in Javascript. In order to simplify the understanding, the first half of the shaving is temporarily related to the execution Context. In addition this article is the personal opinion, if has the question or the Non-positive support, Welcome to propose correction and the discussion!

Directory
    • Objective
      • Reference sources
    • Variables and values
      • Distinguishing variables from values
      • Two major types of JS values
      • The difference between heap memory and stack memory
    • Values vs. objects
    • Combine execution context understanding
Preface reference Source

walnuts, background shade, This article references the following sources

    • Uncle tom: Variable Object
Variables and values differentiate between variables and values

Like all other programming languages, JavaScript also has variables and concepts worth

var a = 10; A is a variable, 10 is a value (base type) var b = {}; B is a variable, {} is a value (reference Type)

As in the above code, the left side of the = sign is the variable, and the right side of the = is the Value.

Two major types of JS values

The concept of variables and values is mentioned earlier, followed by a brief introduction of the values

The values of JavaScript fall into two main types:

    • One is the basic data type (also called the basic type, the original type), only five kinds (undefined,null,number,boolean,string)

      The basic type is characterized by the inability to change after the definition, stored in the stack memory (it can be understood as a Constant)

    • A class is a complex data type (also called a reference type, an object type), with only one

      The characteristic of a reference type is that after the definition, the value can be changed, the stack memory only holds the variable identifier and pointer, and the specific data is stored in the heap memory (so can be changed)

      Object.prototype can be understood as the mother of all things, all other types of objects can be understood as it is produced (such as built-in type array,date, etc.), there is a more special function type (its prototype is Function.prototype , and in fact the prototype is based on object.prototype, the details need to refer to the prototype of the series behind the Article)

    • For more information: JavaScript data types

For storage of basic types and reference types, you can use the understanding

    • That is, if the value of the variable 1 becomes 102, the actual in-stack memory of 101 is not changed, but only in the stack memory of a new one, to store 102 of this Constant. Then point the variable 1 to 102.

    • and the variable 2 because the stack memory is a pointer, the actual execution of the heap in memory data, so the value of the variable 2 can be arbitrarily changed (the data in the heap memory can be changed)

The difference between heap memory and stack memory

What is the difference between the heap memory and the stack memory?

    • Stacks are automatically allocated and recycled during their lifetimes. Faster.
    • Larger heap Space. Controlled by the User. The life cycle is controlled by reference Counting. The collector to release the final heap space

And the previous basic type and the reference type of heap, stack allocation, can be understood as follows:

    • Basic type General data is Small. So with the stack, the speed is fast
    • Reference types have a count and heap to control the release mechanism
Values vs. objects

As mentioned above, the relationship between variables, values, and objects is summarized as Follows:

    • var variable = value; There are only two types, one is a basic type (similar to constant Data) and one is a reference type (object)
    • That is, the = number to the left is the variable, the right side of the = number is the value, and the value can take two types, one is the basic type (similar to the constant data, stored in the stack memory), one is the reference type (that is, the object, stack memory pointer, point to heap memory).
Combine execution context understanding

The variables, values, and objects of JavaScript are explained Above. next, in conjunction with the execution context of JS in-depth Explanation.

Please look forward to ...

JavaScript building blocks (i) variables, values, and objects

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.