How it works...

Using the get keyword creates a read-only property that has a function for a value. We return a string from that function, so that,when the property is read, that value is returned. However, because it is read-only, a run-time error is thrown when we try to write to it.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.