JavaScript Function Parameters

I do apologise if a post like this is not allowed, but I had no where else to go. I watched an explanation on YouTube of function parameters, but it did not make sense. I went to YouTube to see if I could get a verbal explanation of functions since I learn better that way. The YouTube video explained that we have to “call the function” by doing mList[i](), but how in the world is that calling the function when there is no function here called function mList()? The only function is visitCarnival(mList). Video in question is JavaScript Function Parameters - YouTube

const beer_cost = 6.75;
const burger_cost = 5.00;
const pop_cost = 3.00;

let account_balance = 15.75;

// drink beer
function drink_beer() {
    account_balance = account_balance - beer_cost;
    console.log(account_balance);
}

// eat a burger
function eat_burger() {
    account_balance = account_balance - burger_cost;
    console.log(account_balance);
}

//drink pop
function drink_pop(params) {
    account_balance = account_balance - burger_cost;
    console.log(account_balance);
}

let mealList = [drink_beer, drink_pop, eat_burger, drink_beer];
function visitCarnival(mList) {
    for (let i = 0; num = mList.length; i < num; i = i + 1) {
        mList[i]()
    }
}
visitCarnival(mealList);

mealList is an array containing all the functions. The for loop in visitCarnival iterates through the this array of functions (called mList inside the function due to the parameter name) and executes each of them. That is what mList[i]() does.

In the first iteration i = 0, so it executes mList[0] which is really just the function drink_beer. This means that is is really drink_beer() in the first iteration.

This calls visitCarnival and passes the mealList array as the function’s argument. Inside the function, mList is a reference to mealList.

I guess I just still do not understand how mList() is a function if it’s not even a function

mList is not a function. It is an array like I told you before.

mList[0], mList[1], mList[2], and mList[3] are functions. That is why it is mList[i]() and not mList().

Ah ok. Yes, I understand that mList is an array. What makes mList[0] a function? I ask because it is not

function mList (param) }
}

It looks like a variable wanting the index versus a function

(sorry, learning disability)

What is the first element in the mList array?

The first element is drink_beer

Yes. And what data type is drink_beer?

I believe It is a list

Oh wait. It was a function at the very top

Then made into a list

It hasn’t been made into a list. It’s a function that has been put into a list.

yeah sorry that’s what I meant lol

Right, so it’s still a function, so you can call it, cause it’s still a function.

Lol exactly — I’ve realised that spending hours learning without breaks is NOT the way to go. The next day, I watched the YouTube lesson again and I completely understood why. Thank you all for your assistance.