So, according to MDN docs :
class Rectangle {
height = 0;
width;
constructor(height, width) {
this.height = height;
this.width = width;
}
}
By declaring fields up-front, class definitions become more self-documenting, and the fields are always present.
As seen above, the fields can be declared with or without a default value.
At first I thought that if I create an object using the constructor above and don't pass height and width arguments, I would have height = 0. However, it's not a case. It is undefined.
let rectangle = new Rectangle()
console.log(rectangle.height) // this is undefined
So, now I can't understand the point of public field declarations. They look like extra lines of code without much of purpose. What benefits do they bring? Thanks for any explanations.