How to ensure that my enum values in JavaScript don't change?
Hello everyone! I'm writing in JavaScript and encountered a problem: I'm creating an object that I use as an enum for order statuses. For example:
```javascript
const OrderStatus = {
PENDING: 'pending',
SHIPPED: 'shipped',
DELIVERED: 'delivered',
CANCELLED: 'cancelled'
};
```
But I noticed that other developers on the team, or even myself, might accidentally change the values of this object during program execution. For example, someone might write `OrderStatus.PENDING = 'new_pending'` and break all the logic. TypeScript has proper enums, but we're writing in pure JS.
I've tried using `Object.freeze()`, but I'm not sure if it's 100% protection against changes. Maybe there's a more reliable way to make enum constants immutable? How to properly organize an enum in
No answers yet.
Log in to leave an answer