How can you make the properties of an object immutable in JavaScript?
- Using Object.freeze()
- Using Object.preventExtensions()
- Using Object.seal()
- Using Object.makeImmutable()
To make the properties of an object immutable in JavaScript, you can use the Object.freeze() method. This method prevents any changes to the object's properties, making them read-only. The other options, Object.preventExtensions() and Object.seal(), allow some level of modification but not full immutability, and Object.makeImmutable() is not a valid method in JavaScript.
Loading...
Related Quiz
- You are developing a high-traffic e-commerce website. You need to implement a caching strategy to ensure that the load on the database is minimized, and the data retrieval is fast. Which caching strategy would be most suitable, and why?
- You are developing a system with stringent data integrity requirements. How would you design the schema to enforce data integrity constraints and handle violations effectively?
- Which Node.js package is commonly used to connect to a MySQL database?
- What is the primary purpose of using JSON Web Tokens (JWT) in authentication?
- In Express.js, middleware functions have access to the request object, the response object, and the ______ function.