Hi, in the Functions — reusable blocks of code section of the MDN js course, they mention how by using parameters, you can eliminate the problem of “myValue” variable not being defined in the other subfunctions of the big function.
function myBigFunction() {
var myValue = 1;
subFunction1(myValue);
subFunction2(myValue);
subFunction3(myValue);
}
function subFunction1(value) {
console.log(value);
}
function subFunction2(value) {
console.log(value);
}
function subFunction3(value) {
console.log(value);
}
For some reason i cant wrap my head around how this works. Why is the parameter set to “myValue” in the big function yet in each individual sub function its only set to “value”. I would very much appreciate an explanation on scope and parameters in general. Thank you!