Type and function parameters of JS value

Source: Internet
Author: User

The parameters of all functions in JavaScript are passed by value !

Since the values in JS are divided into primitive type values and reference type values , the function differs from the external value change.

A primitive type value refers to a simple data segment, whereas a reference type value refers to an object that may consist of multiple values.

5 Basic types (Undefined Null String number Boolean) are accessed by value and can manipulate the actual values saved in the variable;

The value of a reference type is an object that is held in memory, and JavaScript does not allow the user to directly access the in-memory location, while manipulating the object, actually manipulating the object's reference rather than the actual object, so that the value of the reference type is accessed by reference .

When copying the value of a variable, the base type copies the value directly, and the reference type value copies its own value, but it is itself and the copied copy, which is a pointer to an in-memory object.

Therefore, the parameters of the function are passed by value, except that the value itself has the actual value and the pointer.

Now to understand this sentence:JavaScript string is immutable ! None of the methods defined by the string class can alter the contents of a string. A method like String.touppercase () returns a completely new string instead of modifying the original string.

Because string is the basic data type in JS, when the function is called, the copied value is passed, and the copied value is changed, and the original value is there.

Type and function parameters of JS value

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.