[Solved] Why can’t we declare a local variable inside of function parentheses, in JavaScript?


In a comment you’ve clarified:

I know [it isn’t allowed] but I just wondered why isn’t it allowed

Because until ES2015 it would have been completely redundant and pointless; just having minLength there is sufficient declaration, since JavaScript’s variables and parameters are not typed. Moreover, var would have been misleading, as minLength isn’t a variable, it’s a parameter. (Functionally, they’re very nearly the same thing as far as the function’s code is concerned other than the obvious difference that the initial value of a parameter comes from outside the function; but they aren’t the same thing.)

In ES2015 and above, there’s an argument for allowing an optional const to indicate that the parameter’s value can never be changed by the function, but I haven’t seen any proposal for that advanced (so far).

0

solved Why can’t we declare a local variable inside of function parentheses, in JavaScript?