CallBack Function Example With Demo

 Definitaion:- Functions that are used as an argument to another function are called callback functions.

Code:-

function divideByHalf(sum){
  console.log(Math.floor(sum / 2));
}

function multiplyBy2(sum){
  console.log(sum * 2);
}

function operationOnSum(num1,num2,operation){
  var sum = num1 + num2;
 // console.log(sum)
  operation(sum);
}

operationOnSum(33divideByHalf); // Outputs 3

operationOnSum(55multiplyBy2); // Outputs 20

No comments:

Post a Comment

CPU vs GPU Architecture

  CPU vs GPU Architecture CPU (Central Processing Unit) and GPU (Graphics Processing Unit) have distinct architectural differences, optimize...

Best for you