Can global constants be declared in JavaScript?

前端 未结 8 863
耶瑟儿~
耶瑟儿~ 2020-12-16 09:33

If so, what is the syntax for such a declaration?

8条回答
  •  余生分开走
    2020-12-16 09:51

    If you want to make sure the value cannot change use a function.

    So, instead of:

    var Const_X=12
    

    use:

    function Const_X() {
    return 12;
    }
    

提交回复
热议问题