Modifiers - Protecting from change - ReadOnly

3 important questions on Modifiers - Protecting from change - ReadOnly

There are times that we want a property to be immune from change.

How can we do this?

Make the property private.
Report

What is a downside of making the property private?

We can make the property private, which will be a help, but that only stops changes that originate outside of the instance.
Report

What stronger form can we use instead of private?

If wish this to be stronger, we can add {readOnly} to the property.

This indicates that the property should be protected from all changes once it is initialized.
Report

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart