JavaScript const Keyword

前端 未结 8 1676
自闭症患者
自闭症患者 2020-12-09 13:25

Does the const keyword in JavaScript create an immutable reference to immutable data structures? [I\'m assuming that immutable data structures exist in JavaScri

8条回答
  •  隐瞒了意图╮
    2020-12-09 13:39

    Yes, it does create an immutable reference, but it is not been standardized and is not supported in all browsers.

    See this MDN article on the const keyword for details and compatability.

    However, it doesn't do anything to set the referenced data structure as immutable. Several answers below address that question using, for example, Object.freeze

提交回复
热议问题