Javascript Functions : "orderCount" and "itemCount" variables


In the Functions sections of the Intro course the JavaScript there is a part where you end with this code while learning about “return”.

let orderCount = 0;
const takeOrder = (topping, crustType) => {
  console.log('Order: ' + crustType + ' pizza topped with ' + topping);
const getSubTotal = (itemCount) => {
  return itemCount * 7.5;

takeOrder('mushroom', 'thin crust');
takeOrder('spinach', 'whole wheat');
takeOrder('pepperoni', 'brooklyn style');

Can someone explain to me the correlation between “itemCount” and “orderCount”? where does itemCount get its value and why wouldn’t it be “return orderCount * 7.5” and so on? Thanks in advance!


In the above call we pass the global as the argument, which becomes itemCount locally in the function.


So, you mean since ‘orderCount’ is a global variable it can be passed in a local variable as argument, changing the value of the local variable’s argument?


We can use the global as an argument which we pass to the local parameter. The parameter will point to the same object, but if it is changed inside the function, it will no longer point to the global object (unless the object is an Array or Object).


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