JS elevation basic type and value of reference type learning notes

Source: Internet
Author: User

The ECMAScript variable may contain values for two different data types: the base type value and the reference type value.

Created in a similar way: Create a variable and assign it a value. (1) Comparison of base type values and reference type values
base type value reference type value
Undefined, Null, Boolean, number, and String
stack memory saved in in

(2) Copy variable value

I. Procedure for copying a type value:

If you copy the value of the base type from one variable to another, a new value is created on the variable object, and the value is copied to the location assigned to the new variable.

II. Procedures for copying reference type values:

When a value of a reference type is copied from one variable to another, the value stored in the variable object is also copied into the space allocated for the new variable. The difference is that a copy of this value is actually a pointer to an object stored in the heap.

(3) Parameter transfer

The parameters of all functions in ECMAScript are passed by value . That is, the delivery of a primitive type value is like a copy of a primitive type variable, whereas a reference to a value of a type is the same as a copy of a reference type variable.

(4) Detection type

detecting basic data Types: The typeof operator is the best tool for determining whether a variable is a string, a numeric value, a Boolean, or a undefined. detecting the type of value/object of a reference type: The instanceof operator always returns True when the instanceof operator detects a reference type value and an Object constructor, and the operator always returns false if the value of the base type is detected using the instanceof operator. Because the base type is not an object. *ECMA-262 specifies that any object that implements the [call] method internally should return "function" when the typeof operation is applied. Applying typeof to regular expressions in different browsers returns different values, function or object.

JS elevation basic type and value of reference type learning notes

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.