A code example from a JavaScript book. I am learning about passing functions as arguments to functions. The solution explains that when we pass the hawaiianTranslator function to the sayIt function that the string "hello" is the argument for hawaiianTranslator.
Can someone please explain very simply why this is. sayIt doesn't return anything so why/how is the value of phrase being passed to the hawaiianTranslator function.
Thank you in advance
function sayIt(translator) {
var phrase = translator("Hello");
alert(phrase);
}
function hawaiianTranslator(word) {
if (word === "Hello") return "Aloha";
if (word === "Goodbye") return "Aloha";
}
sayIt(hawaiianTranslator);
sayIt(hawaiianTranslator); alerts "Aloha". How does this happen? I don't understand how the string "hello" is the argument to the function hawaiianTranslator