Skip to content

Commit eedbaf5

Browse files
committed
Class Object try catch block in JS
1 parent afee1ce commit eedbaf5

4 files changed

Lines changed: 165 additions & 0 deletions

File tree

Class & Object & Try Catch.docx

1.56 MB
Binary file not shown.

Class & Object & Try Catch/app.js

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
const student = {
2+
FullName: "Nilaj Chakraborty",
3+
Marks: 94.3,
4+
printMarks: function(){
5+
console.log("Marks =",this.Marks)
6+
}
7+
8+
};
9+
10+
11+
const employee = {
12+
calculateTax(){
13+
console.log("Tax rate is 10%");
14+
}
15+
16+
};
17+
18+
const KaranArjun ={
19+
salary: 50000
20+
};
21+
22+
const RahulRaj ={
23+
salary: 60000,
24+
calculateTax(){
25+
console.log("Tax rate is 20%");
26+
}
27+
}
28+
29+
KaranArjun.__proto__=employee;
30+
RahulRaj.__proto__=employee;
31+
32+
33+
34+
class ToyotaCar{
35+
constructor(brand,milege){
36+
console.log("New object created");
37+
this.brand=brand;
38+
this.milege=milege;
39+
}
40+
41+
start(){
42+
console.log("Start");
43+
44+
}
45+
46+
stop(){
47+
console.log("Stop");
48+
}
49+
50+
}
51+
let fortuner=new ToyotaCar("fortuner",10);
52+
console.log(fortuner)
53+
let lexus=new ToyotaCar("Lexus",20);
54+
console.log(lexus);
55+
56+
57+
58+
class Parent{
59+
hello(){
60+
console.log("Hello")
61+
}
62+
}
63+
64+
class Child extends Parent{
65+
66+
}
67+
68+
let obj=new Child();
69+
70+
71+
72+
73+
class Person{
74+
constructor(name){
75+
76+
this.species="Homo sapiens";
77+
this.name=name;
78+
}
79+
eat(){
80+
console.log("Eat");
81+
}
82+
}
83+
84+
class Engineer extends Person{
85+
constructor(name){
86+
87+
super(name);//to invoke parent class constrctor()
88+
89+
}
90+
work(){
91+
console.log("Solving Problem");
92+
}
93+
}
94+
95+
let engobj=new Engineer("Nilaj Chakraborty");
96+
97+
//PQ 2
98+
let DATA = "Secret Information";
99+
100+
class User {
101+
constructor(name, email) {
102+
this.name = name;
103+
this.email = email;
104+
}
105+
106+
viewData() {
107+
console.log("Data =", DATA);
108+
}
109+
}
110+
111+
class Admin extends User {
112+
constructor(name, email) {
113+
super(name, email);
114+
}
115+
116+
edit() {
117+
DATA = "new data";
118+
}
119+
}
120+
121+
let student1 = new User("Nilaj", "nilaj@email.com");
122+
console.log(student1.viewData());
123+
124+
let student2 = new User("Samadrita", "sam@email.com");
125+
console.log(student2.viewData());
126+
127+
let admin1 = new Admin("admin1", "admin1@admin.com"); // Creating an instance of Admin
128+
admin1.edit(); // Now you can call the edit method on admin1
129+
console.log(admin1.viewData()); // This will show the updated data
130+
131+
132+
133+
134+
135+
//try catch
136+
let a=5;
137+
let b=10;
138+
console.log("a =",a);
139+
console.log("b =",b);
140+
console.log("a+b =",a+b);
141+
console.log("a+b =",a+b);
142+
console.log("a+b =",a+b);
143+
try{
144+
console.log("a+b =",a+c);//error
145+
} catch(err){
146+
console.log(err);
147+
}
148+
149+
console.log("a+b =",a+b);
150+
console.log("a+b =",a+b);
151+
console.log("a+b =",a+b);
152+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Objects & Classes in JS</title>
7+
</head>
8+
<body>
9+
10+
11+
<script src="app.js"></script>
12+
</body>
13+
</html>

Class & Object & Try Catch/style.css

Whitespace-only changes.

0 commit comments

Comments
 (0)