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

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

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
raja
Published on 26-Oct-2020 15:52:04
Advertisements