forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
28 lines (22 loc) · 1.12 KB
/
Copy pathclasses.js
File metadata and controls
28 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Student {
// onlyname; // This should not have let or const only in classes
constructor (name, age) { // name and age are arguments given to object at the time of creation of object
this.name = name; // This initializes the local variable as name passed in argument
this.age = age; // This initializes the local variable as age passed in argument
}
}
const Swapnil = new Student("Swapnil", 19); // This way we can create new objects with arguments
console.log(Swapnil.name);// Output Swapnil
console.log(Swapnil.age);// Output 19
class StudentInfo {
// college = "SIES"; // This is allowed above ES7, ES8
constructor (name) { // name and age are arguments given to object at the time of creation of object
this.name = name; // This initializes the local variable as name passed in argument
this.college = "SIES"; // We want the College to be same for all students that's why it is declared outside of constructor
}
getNameAndCollege () { // This is a methon in Stdent
console.log(`${this.name} ${this.college}`);
}
}
const SwapnilInfo = new StudentInfo("Swapnil Bio");
SwapnilInfo.getNameAndCollege();