Weren’t we able to achieve, what getter and setter functions achieve here, earlier as well via simpler methods like :
object_name.property //returns the value of the property
object.property = “New_Value” //modifies the value
Then what is the purpose of using getter setter ??
Your code so far
class Book {
constructor(author) {
this._author = author;
}
// getter
get writer() {
return this._author;
}
// setter
set writer(updatedAuthor) {
this._author = updatedAuthor;
}
}
const novel = new Book('anonymous');
console.log(novel.writer);
novel.writer = 'newAuthor';
console.log(novel.writer);```
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36</code>
**Challenge:** Use getters and setters to Control Access to an Object
**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object