Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Thay đổi giá trị tham số hàm trong JavaScript


Có thể tăng giá trị tham số và gán cho biến khác, trả về giá trị mới.

Ví dụ

Mã thực hiện:

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);

Chạy lệnh:

node fileName.js.

Tên file: demo317.js.

Kết quả

Đầu ra:

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