Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function

Tell us what’s happening:
Describe your issue in detail here.
Can someone explain what is happening in the line
‘this.name = name;’ ?

  **Your code so far**

// Only change code below this line
class Vegetable {
constructor(name) {
  this.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/91.0.4472.164 Safari/537.36

Challenge: Use class Syntax to Define a Constructor Function

Link to the challenge:

Maybe this can help:
https://www.w3schools.com/Js/js_classes.asp

this.name = name;

It creates a property called name and initializes it with the argument passed to the constructor.

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