The semantics of the parameter passed to the function is completely independent of how the parameter was declared (using var , let or const ). What is passed to the function is just some value. The receive function has no visibility of how and where the value was displayed, including, if it is a variable, how this variable is declared. He simply sees the meaning that has been conveyed. The new let and const keywords are not relevant to this behavior.
This is the source of some confusion that attaches value to an array or object that can manipulate this array or object. Therefore, I can do the following:
const a = {}; ax = 1;
const in the above example makes a itself a constant within its scope, so it cannot be re-declared or re-assigned, but it does not in any way prevent the internal structure of a from changing, in this case, adding the x property.
Similarly, in the context of parameter passing:
function func(obj) { obj.x = 1; } const a = {}; func(a);
Here func gets the value of a as obj , but with this value it can access / change the interiors of the object.
Possible interest: How to set a parameter constant in JavaScript? .
user663031
source share