Concept of return in functions- Not Cleared!

<In the below given link of the exercise on using functions, I am not clear between the concept of using and calling functions with parameters: orderCount and itemCount>


Replace this line with your code.

<do not remove the three backticks above>

A function is a block of code, which we can execute by calling it.

The return statement ends function execution and specifies a value to be returned to the function caller.

return means literally that, you return (hand something back) to the function call, which you can then log to console or store in a variable:

function getSubTotal(itemCount){
  return itemCount * 7.5

takeOrder('bacon', 'thin crust')
takeOrder('bacon', 'thin crust')
takeOrder('bacon', 'thin crust')

let x = getSubTotal(orderCount) // returned value is stored in x
console.log(x) // logging x (returned value) to console

here we declare our function:


with parameter itemCount, then we call the function with argument itemCount (values supplied at function call are arguments, not parameters)

the value of function argument (itemCount in this case) is passed along to orderCount, if it helps, you can think of it as this:

orderCount = itemCount

when the function is called, hope that helps


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