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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *