Primitive types
In javascript number, strings, boolean fall under the category of primitives.
And whenever such types are passed as arguments to a function, a separate copy is created inside the function scope which has no impact on the outer scope
for e.g
var number_1 = 32;
var number_2 = 43;
addition(32,43);
//number_1 is 32 here
//number_2 is 43 here
function addition(number_1,number_2) {
number_1 += 1; // number_1 is 33
number_2 += 1; // number_2 is 44
}
Reference types
Reference types are slightly different
Take the following example
var obj = new Object();
fn(obj);
function fn(object){
object.property = "test";
//obj.property is "test"
object = new Object();
object.property = "test 2";
//obj.property is still "test"
//obj.property should have changed to "test 2",
//if it had been passed by reference
}
if it had been passed by reference , obj.property
should have got changed to "test 2" after the last statement inside fn, but it didnt.
so when passing reference values to functions, a separate copy of the pointer to the object is passed.