Skip to Main Content
JavaScript Absolute Beginner's Guide, 2nd Edition
book

JavaScript Absolute Beginner's Guide, 2nd Edition

by Kirupa Chinnathambi
December 2019
Beginner content levelBeginner
464 pages
10h 31m
English
Que
Content preview from JavaScript Absolute Beginner's Guide, 2nd Edition

17. Getters and Setters

In This Chapter

  • Learn the difference between data properties and accessor properties

  • Learn about getters and setters

  • Identify when to use an accessor property vs. a data property

The properties we have been working with so far are known as data properties. These are the properties where we give them a name and assign a value to them:

let foo = {
  a: "Hello",
  b: "Monday";
}

To read back the value, all we do is just access it directly:

console.log(foo.a);

Writing a value to this property is sorta what we would expect as well:

foo.a = "Manic";

Outside of setting and reading a value, there really isn’t much more we can do. That is the sad tale of a data property. Now, as part of reading ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript Absolute Beginner’s Guide

JavaScript Absolute Beginner’s Guide

Kirupa Chinnathambi

Publisher Resources

ISBN: 9780136204213