I'm new in JavaScript and just trying to figure out abut this code of line.
As far as I know, the word operator is just a random word that could have been anything. But how does it know that the users is referencing to the word add/subtract/multiply/divide when those word also could have been anything else, and lets say its a bunch of other function in that .js file. How does operator return the right inputs?
function add(num1, num2) {
return num1 + num2;
}
function subtract(num1, num2) {
return num1 - num2;
}
function multiply(num1, num2) {
return num1 * num2;
}
function divide(num1, num2) {
return num1 / num2;
}
function calculator(num1, num2, operator) {
return operator(num1, num2);
}