JavaScript raw values and object reference instance analysis

Source: Internet
Author: User
Tags arrays comparison

 JavaScript raw values and object reference instance analysis

This article mainly introduces the JavaScript original value and the object reference method, the example analyzes the JavaScript original value and the object reference function, the definition and the related technique, needs the friend to be possible to refer to under

The examples in this article describe JavaScript raw values and methods for object references. Share to everyone for your reference. The specific analysis is as follows:

In a word: The original value is immutable, and the object reference is mutable.

The original values in JS (Undefined, null, Boolean, numeric, and string) are essentially different from objects (including arrays and functions). The original value cannot be changed, and no method can change an original value; for strings, all the methods in the string appear to return a modified string, which actually returns a new string value:

?

1 2 3 var str= "Hello World"; S.touppercase (); S is still the same

The comparison of the original values is a comparison of values: they want to wait only if their values are equal.

Objects differ from the original values, first they are mutable, and then the comparison of objects is not a comparison of values; objects are compared by reference: they want to wait only if they reference the same base object.

To compare 2 separate objects or arrays, you must compare their properties or elements as follows:

?

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.