In the second example using param would be treated the same as if it were defined as a local variable with const instead of let .
This would provide the same benefits as const for function parameters, i.e. readability, indicating intent, avoiding accidental modification of parameters, etc.
This would be extended to default parameters, e.g.
function foo(const param = 0)
{
// ...
};
Perhaps for consistency let should then also be allowed to explicity indicate a mutable parameter? e.g.
FWIW, this is something that I wouldn't mind having. @mikesamuel has a good point regarding catch blocks, but the rest of the comment seems absurd to me, as both var and let in that position wouldn't change the semantics.
OTOH, being able to guarantee that the binding of the parameters won't change sounds like a good ergonomic addition.
This is about ensuring the language itself provides guarantees. Linters don't do that. That's why const for variable declarations is part of the language itself, rather than a linter check, and this proposal is an extension of that.
It's a good point about backwards compatibility and consistency. It seems like the easiest option for compatibility is to only support const for function parameters and not let or var. But this does make it kind of inconsistent with variable declarations. On the other hand, you could argue since function parameters never needed let or var and have always defaulted to mutable, there's no need for them to be supported in function parameters. Since only const would actually change anything about the parameter, perhaps it is actually fitting that only the const keyword is supported in parameters.
This is about ensuring the language itself provides guarantees. Linters don't do that. That's why const for variable declarations is part of the language itself, rather than a linter check, and this proposal is an extension of that.
Engines have optimizations for "effectively-constant" variables, with Edge being the first and V8 following suit not long after. If it's statically analyzable, engines can generally infer it - it's the runtime values they struggle with the most.