So let’s start with const
Const, like the LET feature, has block-level scope
Difference: A variable defined by const cannot be modified
A const variable must have a value after it is defined. It cannot be assigned as a constant
To keep complex data types from changing, const obj = object.freeze
Object.freeze() to completely freeze an Object (array)
Const obj ={a:1} obj. A =2 obj. B = 3 console.log(obj) {a:2,b:3 Freeze ({a:1}) obj2.a=2 obj2.b=2 console.log(obj2)Copy the code
Freeze freezes values in heap memory, not references in the stack
Object.freeze() allows performance optimization
Refer to the vue source code, when defining the reactive type, if the freeze data, do not add the setter and getter.
Note: VUE no longer internally listens for data changes to improve performance
Object.seal() freezes an Object property.
The difference between Object.seal() and Object.freeze () is that object.seal () freezes an Object whose value can be changed but whose properties cannot be added
Freeze ({a:1}) obj2.a=2 obj2.b=2 console.log(obj2) {a:1} const obj3 = object.seal ({a:1}) Obj3. a=2 obj3.b=2 console.log(obj3) {a:2}Copy the code