What is the javascript
equivalent for typescript
's const assertion?
const arr = [1,2,3,4] as const
I want to achieve this array
in javascript to avoid further mutation.
What is the javascript
equivalent for typescript
's const assertion?
const arr = [1,2,3,4] as const
I want to achieve this array
in javascript to avoid further mutation.
Yes, Use Object.freeze
const arr = [1, 2, 3, 4, 5];
Object.freeze(arr);
arr.push(8); // Uncaught TypeError: Cannot add property 5, object is not extensible