Functional arguments
Course: Asynchronous Javascript, Callbacks and more - chapter 7
Write a calculator program that adds, subtracts, multiplies, divides two arguments.
Approach #1
Section titled “Approach #1”Calling the respective function
function sum(a, b) { return a + b;}
function multiply(a, b) { return a * b;}
function subtract(a, b) { return a - b;}
function divide(a, b) { return a / b;}
function doOperation(a, b, op) { return op(a, b)}
console.log(sum(1, 2))Approach #2
Section titled “Approach #2”Passing in what needs to be done as an argument.
function sum(a, b) { return a + b;}
function multiply(a, b) { return a * b;}
function subtract(a, b) { return a - b;}
function divide(a, b) { return a / b;}
function doOperation(a, b, op) { return op(a, b)}
console.log(doOperation(1, 2, sum))