JS in the type:
2 large types: primitive types and objects.
The original type has a Boolean, number, string of three ordinary primitive types, plus null, undefined these two special primitive types
Objects are more, ordinary objects, built-in objects, global objects, functions, arrays, and so on.
function Parameter pass type:
For the original type, the value is passed, i.e. a copy of the incoming function is copied, and the modification within the function does not affect the external variable itself.
For an object type, an address is passed, and an external variable changes when the object is modified inside the function.
pay attention to this situation! refer to the following code:
var omyobj = {name: "Robert"}; function Test (obj) { = "Ah!!! "; = {Name: "Ah ~ ~ ~"};} Test (omyobj); alert (omyobj.name);
On the surface of the internal redefinition of the variable, it should be the result is "Ah ~ ~ ~" is right, but the result is "Ah!!! ”。
The reason is passed by address, and when test executes, it re-declares an obj local variable, which points to the external Omyobj object. So the first line of the function works. However, when obj = {name: ' ~ ~ ~ ' occurs, it changes the point of obj to the new object and does not affect the point of the external omyobj.
Type and function parameter Transfer type problem in JS