value = data.amount1 + data.amount2;
There are a two things wrong with this approach.
- You can not be certain that amount1 or amount2 exist.
- You can not be certain that amount1 or amount2 are acutally numbers.
To combat this problem, the calculation should be written as follows:
if(data.amount1 && data.amount2) value = parseInt(data.amount1) + parseInt(data.amount2);