-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63-class.js
More file actions
42 lines (37 loc) · 852 Bytes
/
Copy path63-class.js
File metadata and controls
42 lines (37 loc) · 852 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Class keyword was introduced in ES6 to reduce the workload of creating prototypes seperately
// Class can contain constructor and methods and objects of class needs to be created using "new" keyword
class CreateUser {
constructor(firstName, lastName, email, age, address) {
this.lastName = lastName;
this.firstName = firstName;
this.email = email;
this.address = address;
this.age = age;
}
about() {
return `${this.firstName} is ${this.age} years old.`;
}
is18() {
return this.age >= 18;
}
sing() {
return "Unstoppable";
}
}
const user1 = new CreateUser(
"Vaishnao",
"Wankar",
"vaishnao@gmail.com",
21,
"India"
);
const user2 = new CreateUser(
"Vaibhav",
"Shirole",
"vaibhav@gmail.com",
22,
"India"
);
console.log(user1);
console.log(user2.sing());
console.log(user1.is18());