The constructor GUARANTEES that any initialization code gets called. This frees you from having to explicitly call such code each time you create an object. Also, this means anyone else that creates one of your objects doesn't have to call intialization code. You can create several constructors which allows you the flexibility to default certain values. You can create a constructor where the user has to pass in all the initialization parameters -- i.e.,
myObject(a, b, c, d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
You can create a constructor where none of the values are passed and you default all of them. i.e.,
myObject() {
this.a = 1;
this.b = 2;
this.c = 3;
this.d = 4;
}
And of course you can do something inbetween where only some of the parameters are passed to the constructor:
myObject(a, c) {
this.a = a;
this.b = 2;
this.c = c;
this.d = 4;
}