Object.freeze() vs const

前端 未结 5 473
感情败类
感情败类 2020-12-12 10:27

Object.freeze() seems like a transitional convenience method to move towards using const in ES6.

Are there cases where both take their place in the cod

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 10:37

    const and Object.freeze are two completely different things.

    const applies to bindings ("variables"). It creates an immutable binding, i.e. you cannot assign a new value to the binding.

    Object.freeze works on values, and more specifically, object values. It makes an object immutable, i.e. you cannot change its properties.

提交回复
热议问题