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.

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.

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.

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