let number = 100
function change(number) {
number = number * 10;
}
change(number);
console.log(number);
The above code outputs 100, whereas
let number = 100
function change(blah) {
number = number * 10;
}
change(number);
console.log(number);
outputs 1000
Can someone explain why the number is not updating its value inside the function when the parameter name is also "number"?
blah,numberis not defined anywhere inside the function, so it refers to the global variable. When you name the parameter asnumber, it becomes a local variable, which won't affect the global one