Class Example
class users{ ///creteing class
constructor(name,age){ //declare constructor
this.name =name;
this.age=age;
}
getName(){
this.email ="dev@gmail.com";
return this.name;
}
getAge(){
return this.age;
}
getEmail(){
return this.email;
}
}
///now crete object of class
var user = new users("kamal","26");
console.log(user.getName())
console.log(user.getAge())
console.log(user.getEmail()) ///agar getName() function define ne rhege pahle to undefine k error ayega
OUTPUT
kamal
26
dev@gmail.com
No comments:
Post a Comment