In JavaScript, when a function is called with arguments, the arguments are passed by value, not by reference. This means that if you pass a variable to a function, the function creates a new local variable (the parameter) and assigns it the value of the argument at the time of the call. Subsequent reassignments to the original variable outside the function do not affect the value stored in the function's local parameter or its closure.
function getLogger(arg) {
function logger() {
console.log(arg);
}
return logger;
}
let fruit = 'raspberry';
const logFruit = getLogger(fruit);
logFruit(); // "raspberry"
fruit = 'peach';
logFruit(); // "raspberry" (Still prints the original value because 'arg' was a copy of 'fruit' at call time)