the value of the argument at function call (orderCount) get passed to the function parameter (itemCount), so under the hood, if it helps, this is what happens:
itemCount = orderCount
which in programming terms is assigning the value of orderCount to itemCount. This is happening when the function is called
the ironic thing is, nearly no one has problems earlier in this track when we build takeOrder function, where we use exactly the same thing (parameters and arguments)
ItemCount is just a place holder, so it could be anything
console.log(getSubTotal(orderCount));
you can see that when the function getSubTotal called inside the console.log, there is orderCount as a paramater. The orderCount is basically replacing the place holder aka itemCount and passes his value to the getSubTotal function (the value is 3 of course). And that’s how the computer knows to “replace” itemCount with orderCount. I hope that my explanation help you.
Okay, that makes a bit more sense. so you could even put like ‘puppiesAreAmazing’, instead of ‘itemCount’. but if that’s the case and it’s just holding the place of orderCount, why don’t we just write orderCount? Why do we have to implement a placeholder parameter? I don’t really see the purpose.
Hi @shearmadness, if you don’t mind me chip in a little while waiting others to reply, I hope to share my thoughts on this subject which I wrote some time ago, it was quite long, but some parts of it touched upon your doubts and question. If you have some time to spare, you can refer it here (Disclaimer: the examples there were using ES5 syntax, not the latest ES6).
@stetim94 does bring up a very good point about the irony of this matter:
I once cataloged few @stetim94’s answers about this ‘itemCount’ matter for another user, you can read it here if you’re curious about what others have been asking too.
using orderCount as a parameter will work too. However, it is best avoid using orderCount or any same Name as a parameter when it exists as a variable itself. Is to reduce confusion or accidental error.