1

Below is a code for ordering a pizza. One thing I didn't clearly understand is that getSubTotal has a parameter itemCount and at the end of the line when the function getSubTotal is called the argument inside it is orderCount and not the parameter itemCount. Is it because orderCount is the argument for the itemCount?

Hope I explained my question clearly.

var orderCount = 0;

function takeOrder(topping, crustType) {
  console.log('Order: ' + crustType + ' crust topped with ' + topping);
  orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
  return itemCount * 7.5;
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log(getSubTotal(orderCount));

Thank you.

Bibek Sharma
  • 73
  • 1
  • 2
  • 8

3 Answers3

0
var b=10;
function abc(a){
    return a*10;
}

c=abc(b);
console.log(c);

This is what you need. You are basically passing the value of b in

Nitesh Rana
  • 512
  • 1
  • 7
  • 20
0

orderCount is the value that gets passed to the function in the function call, while itemCount is what it gets bound to in the function body. In other words, it's the difference between formal parameter and actual argument.

Community
  • 1
  • 1
danlei
  • 14,121
  • 5
  • 58
  • 82
0

Exactly. When you call getSubTotal(orderCount) the function is called with the value of the global variable orderCount. At the beginning of the function call, the parameter itemCount is set to the value of orderCount, then instructions are executed that compute a value which is then returned. Then the expression getSubTotal(orderCount) equals to the returned value.

orderCount is called an effective argument (a name or value passed to the function) and itemCount a formal argument (a name to denote the value passed inside the function).

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69