Use class Syntax to Define a Constructor Function.?

I did not understand this exercise. Anyone can explain me the solution below?
Your code so far


class Vegetable {
constructor(name) {
  this.name = name;
}
}

const carrot = new Vegetable("carrot");
console.log(carrot.name); // => should be 'carrot'
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36.

Challenge: Use class Syntax to Define a Constructor Function

Link to the challenge:

You need to have a function to print the name of the vegetable.

class Vegetable {
constructor(name) {
this.name = name;
}
getName() {
return this.name
}
}

const carrot = new Vegetable("carrot");
console.log(carrot.getName); //should return "carrot"

(at least that’s the way I would do it)

yeah, but what I didn’t understand was the use of this sintax:
class
constructor
and this.
Why do I need to use them? didn’t understand why that’s useful