0
I am not getting the answer, its showing value is undefined
class Students{ Students (name){ this.name=name; } } var student1= new Students("Omega"); document.write("name"+student1.name);
3 Réponses
+ 5
i think javascript use "constructor" keyword
+ 11
class Student {
constructor(studentName) {
this.studentName = studentName;
}
sayHi() {
return `${this.studentName} says hello & happy SoloLearning!`;
}
}
const student = new Student(`jsStudent`);
console.log(`${student.sayHi()}`);
The function called 'constructor' MUST be named that way (since that is what is run when the 'new' keyword is used).
+ 7
Well, I suggest you to take JavaScript course first.
https://www.sololearn.com/learn/JavaScript/2979/