Basic data type:
Undefined;null;boolean;number;string
These five basic types are accessed by value, because the actual values saved in the variable can be manipulated
Reference data type:
Object
Reference data types are objects that are stored in memory, and JavaScript does not allow direct access to the in-memory location, that is, the memory space of the object cannot be manipulated directly, and when manipulating the object, it is actually the object's reference, not the actual object. When copying a variable that holds an object, the object's reference is manipulated. However, when you add an attribute to an object, the actual object is manipulated)
Parameter passing:
All functions in JavaScript are passed by value, so when a function's formal parameter (in the concept of ECMAScript, which is an element in a arguments object) is a reference data type, it is also passed by value: it copies the address of the object to the parameter, remembering that it is not a reference
eg
function Addten (num) {Num+=10;return num;} var count=20;var result=addten (count), alert (count),//20 value does not change when count copies the value to the parameter num, it is not related to count alert (result);//30
Another example:
eg
function Setnamea (obj) {obj.name: "Monica";} var Person={};setnamea (person); alert (person.name);//"Monica" They only use the same address, although it is passed by value, but the effect is the same as when the reference is passed, so it is often wrongly considered a reference to pass
Take a look at this example:
eg
function Setnameb (obj) {obj.name= "Monica"; obj = new Object (); Obj.name= "Green";} var person={};setnameb (person); alert (person.name);//monica (closure)
Detection type: typeof and Instanceof
var a=undefined; Alert (typeof a);//undefinedvar b=null; Alert (typeof b);//objectvar c=true; Alert (typeof c);//booleanvar d=1; Alert (typeof D);//numbervar e= "Monica"; Alert (typeof e);//stringvar f=new Object (); Alert (typeof f);//object
Instanceof returns TRUE or False
var Person{};alert (person instanceof object),//instanceof is a object? Truealert (person instanceof Array); Instanceof is a Array? Falsealert (person instanceof REGEXP); Instanceof is a RegExp? False
JS Variable Scope memory