Primitive values and complex values in JavaScript

Source: Internet
Author: User

Previous Words

The data types of JavaScript can be divided into two types: primitive type (basic type or simple type) and reference type.

Primitive type: undefined,null,boolean,number,string five kinds;

Reference type: object,array,function;

Corresponding to this, their values are referred to as primitive values and complex values, respectively.

Attribute Original value

The original value is the lowest or simplest form of data or information that is available in JavaScript. The values of the primitive types are referred to as the original values because their values are not fine-grained. That is, the number is a number, the string is a string, and the Boolean value is true and false,undefined and null are undefined and null. These values are simple and cannot represent values that are made up of other values.

An obvious feature of the original value is that it cannot be changed, and no method can change the original value.

var s = "Hello"; s.touppercase (); Console.log (s      ) ; // "Hello"
Complex values

Complex values can have many different types of JavaScript to make up, and complex objects can contain any value, rather than a specific known value.

Objects differ from the original values, they are mutable, and their values can be modified.

var 0 = {x:1= 2= 3; Console.log (o.x);   // 2; Console.log (O.Y);  // 3;
Storage Mode Stack Storage

Because the original value occupies space fixed, is a simple data segment, in order to facilitate the query speed of the variable, it is stored in the stack (stack).

Heap Storage

Because the size of the complex value changes, it cannot be stored in the stack, otherwise it will reduce the query speed of the variable, so stored in the heap (hack), the value stored at the variable is a pointer to the memory of the storage object.

Primitive values and complex values in JavaScript

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.