Now we have a function which will take a variable as argument & that will modify the value. In this case we can sum 10 and return it.
function ModifyValue(x) {
return x + 10
}
const getModifyValue = ModifyValue(10)
console.log(getModifyValue) <em>// 20</em>
Now if you want to do some other things like subtraction, multiplication & division. Then you have to write three separate function.
what if we can tell the function to modify the value according to our needs. Like we will pass the logic what we need instead of write same code multiple times.
function ModifyValue(x, callback) {
return callback(x)
}
function sum(elem) {
return elem + 10
}
function sub(elem) {
return elem - 10
}
const getSumValue = ModifyValue(50, sum)
const getSubValue = ModifyValue(50, sub)
console.log(getSumValue) <em>// 60</em>
console.log(getSubValue) <em>// 40</em>
wow ! Now we can add our different Login in different function. So now the function is pass with argument thats callCallbackfunction.