can someone explain the new operator, dumb it down. I read the MDN DOCs and have a vague understanding but not really sure.
All i know is that it creates a new blank object
and that it links to the constructor for the class syntax .
But like how does it work what does it do?
how does it link with constructor thats what iâm not sure about
here is the code
// 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'
Iâve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the âpreformatted textâ tool in the editor (</>) to add backticks around text.
then we make another object with new?
and since its also name Vegetable it will be link to that class? with carrot being passed into the constructor param?
Also this is my first time coming across the âthisâ keyword, with no explaination whatsoever so confused hahaha