Can anyone provide some insight on how this code is functioning?
I grasp the concept of callbacks but during a tutorial video, I encountered this code snippet:
function addAndHandle(n1, n2, cb) {
const result = n1 + n2;
cb(result);
}
addAndHandle(10, 20, function (results) {
console.log(results);
});
My question pertains to how results
is calculated within the callback. Initially, the result
is passed into the callback in the function declaration which seems logical as the sum is stored in result
. However, later on, I utilize results
, so how does it display the sum of 10
and 20
or any other values assigned to n1
and n2
?