Helper Functions, can u invoke the helper function in a return statement and how is that possible?


I have here another chapter in the Javascript Course, which I dont understand in detail.

function multiplyByNineFifths(number) {
  return number * (9/5);
function getFahrenheit(celsius) {
  return multiplyByNineFifths(celsius) + 32;
getFahrenheit(15); // Returns 59

I am confused by the code return multiplyByNineFifths(celsius) + 32;
I thought, that I need to invoke the function like multiplyByNineFifths(celsius) and assign it to a variable for example and then put the variable in the return statement, but this function has not been invoked. Everything is in a return statement. Is this some sort of short cut for invoking a function or did I miss something (what can I put in the return statement, do I need this intermediate step)?

you could, but you don’t need to. In this case, not using an intermediate variable is better (given the variable doesn’t do anything useful)

the function is invoked on this line:

  return multiplyByNineFifths(celsius) + 32;

javascript will first resolve the call/invocation and the addition before returning

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.