A function is a set of instructions
that can be executed multiple times.
This may sound similar to a loop but
functions are used for a totally
different purpose.
Consider the following example:
In the above code, we are calculating the
cost of each item by multiplying their
respective prices with their quantities.
This process is repeated for each
item individually.
In the above code, we moved the calculation
logic to the calculateItemCost
function.
Therefore, there is no need to repeat the
same code for each item.
This makes the code more organized
and maintainable.