Are there constants in JavaScript?

后端 未结 30 3101
抹茶落季
抹茶落季 2020-11-22 08:53

Is there a way to use constants in JavaScript?

If not, what\'s the common practice for specifying variables that are used as constants?

30条回答
  •  情书的邮戳
    2020-11-22 09:40

    Clearly this shows the need for a standardized cross-browser const keyword.

    But for now:

    var myconst = value;
    

    or

    Object['myconst'] = value;
    

    Both seem sufficient and anything else is like shooting a fly with a bazooka.

提交回复
热议问题