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