Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript Working with Classes in JavaScript Review Working with Classes in JavaScript

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Constructor methods requirement in classes

I just have little question. When are constructor methods not required in a class? I only thought of one instance of this which is one when we don't need any properties, anything else?

1 Answer

Zack Jackson
Zack Jackson
30,220 Points

From what I've gathered, the constructor method is typically used for calling super and for initializing props. Initializing props in the constructor could avoid potential errors downstream in the code if you forget to initialize for some reason. You can also use a constructor method to set default values when initialized.

That being said, I don't think that constructor methods should be used unless it's really necessary to do so.

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

What is 'super'? Also, how can it be not necessary to use the constructor method? Sorry, I just started to learn OOP so I don't know much.