I am using rest parameter to calculate the sum in javascript but as per my code its throwing the following error.
Error::
error: unknown: Rest element must be last element (4:19)
I am explaining my code below.
function add(...num, cb) {
let result= num.reduce((a,i) => {
return a+i;
})
cb(result);
}
add(2,3,4,(item) => {
console.log(item);
})
Here I need to use rest param using add the all value and return result using callback. But its throwing error.