Use class Syntax to Define a Constructor Function - Explanation please

I answered this challenge correctly but I don’t actually understand how it works, any simple explanation please.

I don’t understand what “class & constructor & this” does…

Challenge Link:

Allow me to explain the following terms.

class - defines a blueprint for an object in code. An object contains a group of functions and variables; allowing for proper organization.

constructor - it essentially constructs or builds a new object instance.

this - refers to the instance of the object the method was called on. Not every variable is the same for every version of a class , so this is why we use the keyword this. Using the challenge as a guide, this prevents every Vegetable from becoming a carrot.


I didn’t quite understand this


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.