What is a constructor and other questions

Tell us what’s happening:
Hi, I solved the exercise by looking at the example but I didn’t understand it. I wrote my questions inside the code. Thank you!

Your code so far


// Only change code below this line
class Vegetable{
constructor(name){ //what is constructor and what it's doing here?
  this.name = name; //what is "this"? why do I need to define name = name?//
}
}
// Only change code above this line

const carrot = new Vegetable('carrot');
console.log(carrot.name); // Should display 'carrot'

Your browser information:

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

Challenge: Use class Syntax to Define a Constructor Function

Link to the challenge: