Why no Variables?

Hi guys, this is the answer code from Function >> 6 Return II. It’s about pizza topping and fees.

Two questions:
1: Why do we have the new variable of orderCount from itemCount. I thought they are interchangeable. (Italianized below)
2: Why some functions can have no variables(I bolded them below)


let orderCount = 0;

const takeOrder = (topping, crustType) => {
  console.log('Order: ' + crustType + ' pizza topped with ' + topping);

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

const getSubTotal =         (itemCount)      => {
  return itemCount * 7.5;

const getTax = () => {
 return getSubTotal       (orderCount)       * 0.06; 

const getTotal = () => {
  return getSubTotal (orderCount) + getTax(); 


Would appreciate if you could help.

please read this stackoverflow question:

using global is a bad idea, and you update a global variable within a function, which does not strike me as a good design. This is why itemCount is used, manipulating a global variable directly within several functions is more prone to bugs

Now, for a program as small as you have, its fine. But its not best practice.

they are named parameters and arguments, again, its a design choice. Its up to the programmer to decide what parameters are needed and when no are needed parameters at all

1 Like

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