+ 2
Why use classes if I can use object constructors?
I'm at the following lesson of JavaScript course: https://www.sololearn.com/Play/JavaScript and classes seem pretty similar to how object constructors we learned before work, what's the difference between the two?
1 Answer
+ 7
object constructor is pre-ES6 syntax.
class is ES6 syntax.
By declaring all properties in class constructor and then all class methods in class code block, it makes the code more organized and easier to maintain.