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

2nd Jul 2020, 10:09 AM
C Alpha Beraka
C Alpha Beraka - avatar
3 ответов
+ 5
i think javascript use "constructor" keyword
2nd Jul 2020, 10:11 AM
durian
durian - avatar
+ 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).
2nd Jul 2020, 1:27 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
Well, I suggest you to take JavaScript course first. https://www.sololearn.com/learn/JavaScript/2979/
2nd Jul 2020, 12:16 PM
Raj Chhatrala
Raj Chhatrala - avatar