JS two types of data

Source: Internet
Author: User

The data types in JS are generally divided into two categories, namely: 1value type(base type): Numeric type (number), character type (String), Boolean (Boolean), NULL, and UNDERFINED2Reference type(Class): Functions, objects, arrays, etc.Value type Understanding: The reciprocal assignment of variables,is to open up a new memory space, assign the value of the variable to the new variable and save it in the newly opened memory.After that, the value changes of the two variables do not affect each other; for example: Var a=10;//opens up a memory space to hold the value of variable a "ten"; var b=a;//a new memory space for variable B, saving a value of "10" to the new memory; the value of//a and B changes anyway, Will not affect the value of each other;Reference type Understanding: The mutual assignment of variables, just the exchange of pointers, rather than the object (ordinary object, function object, array object) Copy to a new variable, the object is still only one, just a guide ~ ~; for example: Var a={x:1,y:2}//need to open up memory space to save objects, The value of variable A is an address that points to the space where the object is saved, and VAR b=a;//assigns a guideline address to B, rather than copying a given object and a new memory space to save;//This time through a to modify the properties of the object, then through B to view the properties of the object property has changed; JS Interpreter has its own memory management mechanism, when there is no longer any one reference to an object, the interpreter will consider this object useless, and then recycle the memory resources occupied by this object, the value types are objects (except null and underfined), but they arePseudo-ObjectObjects/pseudo-objects have properties and methods; ECMAScript specifies that all objects have the ToString () method, either an object or a pseudo object; The original/default type of the Number,string,boolean value is a pseudo-object; they all have attributes. Both have the ToString () method; null and underfined have no properties and methods;

JS two types of data

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.