Monday, May 20, 2024
74
rated 0 times [  75] [ 1]  / answers: 1 / hits: 76155  / 9 Years ago, wed, october 14, 2015, 12:00:00

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 code or is there a preferred way to work with immutable data?



Should I use Object.freeze() until the moment all browsers I work with support const then switch to using const instead?


More From » ecmascript-6

 Answers
30

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.


[#64747] Monday, October 12, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;