I am wondering about the variable scope on CSP Unit 7 Lesson 11 Assessment Question #3. (2021-2022)
I didn’t post the code here because it is on the secure assessment.
When I look at the code in the question, I think that the global variable should be unchanged. It doesn’t seem like the function does anything to it. The global variable is simply passed to the function as an argument. But when I run it in App Lab, the global variable is updated.
I made some code that seems analogous, but uses an integer variable instead of a list and the code leaves the global variable unchanged as I expected.
function doMath(num) {
num = num + 5;
}
var x = 11;
doMath(x);
console.log(x);
Can anyone help me understand what is going on? Thanks in advance!