Object Properties & Methods
EasyIn plain terms
Objects have properties (data) and methods (functions). Use getters and setters for computed or controlled access. Property shorthand: { name } instead of { name: name }.
What you need to know
- •Properties and methods
- •Getters and setters
- •Property shorthand
Try it yourself
Copy the code below and run it in your browser console or a code editor:
const obj = {
name: 'Alice',
get greeting() {
return 'Hi, ' + this.name;
},
set name(val) {
this._name = val;
}
};Learn more
Dive deeper with these trusted resources: