I am not getting the answer, its showing value is undefined | SoloLearn: Learn to code for FREE!

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);

7/2/2020 10:09:06 AM

C Alpha Beraka

3 Answers

New Answer

+5

i think javascript use "constructor" keyword

+10

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/