How to make function parameter constant in JavaScript?

Function parameters will stay mutable bindings (like var) in ES6, there’s nothing you can do against that. Probably the best solution you get is to destructure the arguments object in a const initialisation:

function hasConstantParameters(const a, const b, const c, …) { // not possible
    …
}
function hasConstantParameters() {
    const [a, b, c, …] = arguments;
    …
}

Notice that this function will have a different arity (.length), if you need that you’ll have to declare some placeholder parameters.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)