Call By Value :
Value will be different within function and outside of function • IF we change something in the copied variable it will not have an effect on the original variable.
Use if You just want to pass in a value to a function, essentially just copying, with knowledge that inside the function and outside the function will be two different values eventhough they share the same variable name.
/*A copy of the value 5 is being passed to the function. No matter what the function 'f' does, x will be unaffected back in the calling routine. */
var x = 5;
.
.
..... f(x);
**********************************
function testfun(value) {
value = value + 100
console.log("New Value: - " + value);
}
var value = 100;
testfun(value);
console.log('Outside of function: - ' + value);
//OUTPUT
/*Copy sent into the testfun function. original value will be unchanged. */
New Value : - 200
Outside of function: - 100