Can global constants be declared in JavaScript?

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

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

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 09:39

    Javascript doesn't really have the notion of a named constant, or an immutable property of an object. (Note that I'm not talking about ES5 here.)

    You can declare globals with a simple var declaration in the global scope, like outside any function in a script included by a web page:

    
    
                                     
                  
提交回复
热议问题