I have the following code:
function control_function() {
let data = { inputs: [ 'one', 'two'] };
level_one(data);
console.log(data);
} control_function();
function level_one(data) {
data.inputs.shift();
}
And you can see I'm outputting data
, it should give me ['one', 'two']
back, instead it gives me ['two']
, meaning that the function level_one
has, for some reason, affected data that it shouldn't have access to (to write, it has access to it to read, since I'm passing it to the function). I'm signaling to JS that this let data
is only to be used within the control_function
scope and is not to be affected by other functions.
In PHP, this doesn't happen and it makes sense for it not to happen, yet it happens here, which means there's some underlying basic concept I don't understand. What am I doing wrong?