They are both functions that have stored values if I understand this correctly. If that is correct, then I donât understand why I would have to call them a second time?
The two functions were called earlier and returned values. Recalling I define as giving them an updated variable, in this instance. IE they were already called and received values when they were created, so Iâm not understanding why I must insert (ordercount) for each function.
That part returns the same values. Am I understanding the return feature properly? The âreturnâ at the bottom assigns a value to the variable in question?
itemCount is the parameter of the getSubTotal function, which means it has a local scope:
const example = (someParameter) => {
console.log(someParameter);
}
then when we call the function we supply a value for the parameter (in my example the parameter is named someParameter):
// function call
example("some argument for parameter");
if we tried to use the parameter outside the function:
const example = (someParameter) => {
console.log(someParameter);
}
// function call
example("some argument for parameter");
// this will cause an error
console.log(someParameter);
because someParameter has a local scope, it only exist in the example function
âŚand orderCount is defined outside the function so it can be used in anything below. Got it! Thanks for the answer!
This means that the function getSubTotal is supplied by a parameter that exists only locally but when used later in the getTotal function it is called already with the calculation done before by the return thingy, right?