How to make function parameter constant in JavaScript?

后端 未结 8 1084
野的像风
野的像风 2020-12-13 12:43

What I want to do is to use as many immutable variables as possible, thus reducing the number of moving parts in my code. I want to use \"var\" and \"let\" only when it\'s n

8条回答
  •  情书的邮戳
    2020-12-13 13:22

    You can't make a parameter const. Use it as the initial value of a local variable:

    function constParam(a) {
        const const_a = a;
        ...
    }
    

    Note also that const is only supported in Internet Explorer as of IE11. See this compatibility table

提交回复
热议问题