InterviewHubPRO
Section Overview
Q185

Question 185 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

36%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

Why do I need to use the freeze method

In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the final keyword which is used in various languages.

Practical Code Example

javascript
// Why use freeze: Prevents accidental mutation of global constants, Redux initial states, or library configs:
export const APP_CONFIG = Object.freeze({
  ENV: 'production',
  MAX_RETRIES: 3,
  TIMEOUT_MS: 5000
});