Tell us what’s happening:
In the below code is the name of the object I’ve created “carrot” or “name”?
I am a little bit confused as name is a variable representing the string “carrot”, but does the computer just read the variable name when assigning the object private variable and the string when assigning the value?
I hope the way I asked this question makes sense.
**Your code so far**
// Only change code below this line
class Vegetable {
constructor(vegName) {
this.vegName = vegName;
}
};
// Only change code above this line
const carrot = new Vegetable('carrot');
console.log(carrot.name); // Should display 'carrot'
If I changed the code to
constructor(vegName) {
this.vegName = vegName;
The value of this.vegName would still be carrot right? It would just change the object private variable name from name to vegName?
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36
Challenge: Use class Syntax to Define a Constructor Function
Link to the challenge: