Meal maker works without getters and setters why?

Hey there, just completed the Meal Maker project, playing a little with it I’ve seen it works also when deleting the getter and setters methods, so my question is:

Why do you make us set them ?



1 Like

Hello @chip0541501581,

Your observation that the setters and getters are not used in this context is correct. And I understand the confusion.

However you can think of a scenario where you have to use a getter, for instance when you want to see which meals have been added to the list of appetizers. The moment you want to bulk add multiple meals to the menu instead of per meal might be the perfect scenario to implement a setter etc.

Implementing getters and setters is common practice and I can only advise you to always do so. You never know when you might need one :wink:

Happy coding!

1 Like

Hey dude thanks a lot! Wasn’t expecting such a fast answer !

So you’re saying setters and getters are kind of a default set up when creating an object?

I only ask because I tried and I could get this done:

also by just “console.log(menu._courses.appetizers)”

Thanks again ! :v:

1 Like

Yep you are correct.

You can do console.log(menu._courses.appetizers) but then you would have to know how the object is exactly being defined and you have to type an _. Less code and more logical would be to call the getter console.log(menu.appetizers)

Happy coding!


Ok you got me!

Thanks again

have a nice one!

Geez… :smile: I’m sitting here something about hour and try figure out why we need setters and getters in this exercise (except that we can call them in console.log() :expressionless:. I think it will be good to add comment in excersise abaut this. For the beginners (like me) it’s a little confusing.

1 Like

Just to expand on @janneslohmeijer 's answer Getters and setters are to do with the Object Oriented Programming principle of encapsulation. So look at up if you want to better understand why the are used. But 99% of the time (regardles of language) you will use getters and setters and never change anything.


Hahah dude same here !