Computer >> Computer tutorials >  >> Programming >> Javascript

Is it possible to change the value of the function parameter in JavaScript?


Yes, you can increment and assign to some other variable and can return the incremented value.

Example

Following is the code −

function changeTheValueOfFunctionParameter(value) {
   var incrementValue = value + 1;
   return incrementValue;
}
var value = 190;
console.log('The value is:', value);
value = changeTheValueOfFunctionParameter(value);
console.log('After changing the value:', value);

To run the above program, you need to use the below command −

node fileName.js.

Here, my file name is demo317.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo317.js
The value is: 190
After changing the value: 191