Parameters and arguments - Why is it not the exact same as declared?


I am having trouble understanding this code.

Step 5 says, "getSubTotal has a parameter that represents the amount of items ordered. Pass in the orderCount as an argument when making the function call."


But orderCount is not the correct argument. Shouldn't it be itemCount, because that is what was declared in the function i.e.

function getSubTotal(itemCount) {
  return itemCount * 7.5;

Here is the full piece of code:

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('cheese', 'normal');
takeOrder('salami', 'thick');


If I am wrong, could someone please explain why? How is it possible to use an argument that was not declared in the function??



No. itemCount does not exist in the scope where this call is made. orderCount is the global that has been accumulating. itemCount is local, only.


An argument is a value or expression. JavaScript function objects have an arguments object that receives the values passed by the caller. The parameters are arbitrary names we give the items in the arguments object.

Looked at from another angle, the order in which the arguments are stacked is not dependent upon the order of the parameters, but the order of the arguments. The parameters are assigned in sequence, locally.


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