- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcls.js
More file actions
Latest commit
86 lines (68 loc) · 1.69 KB
/
Copy pathcls.js
File metadata and controls
86 lines (68 loc) · 1.69 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
creating class in java
public class Car{
}
*/
//How we create class in javascript
classCar{
/*declare variable with let, var, const
//we can't initialize variable with let, const, var keyword directly inside the class body.
However, We can have variable with having the data type.
*/
fullName="Al Numan";
/*
creating constructor in java->
public Car(){
}
*/
//creating constructor in javaScript
//in javaScript we can have only one constructor either default or parametrize
/*
constructor(){
console.log("default constructor")
}
*/
constructor(make,model,year,color){
this.make=make;
this.model=model;
this.year=year;
this.color=color;
console.log("I won "+year+" "+make+" "+model+" which is "+color+" color");
}
/*
creating method in java
public void car(){
//void type method
}
public int bike(){
return 0;
//return type method
}
*/
//Creating method in javaScript
drive(){
console.log("I drive the car")
}
break(){
console.log("You step on the break")
}
add(a,b){
returna+b;
}
initializingVariableInsideMethod(){
letc=5;
constusCitizen=true;
console.log(this.fullName)
}
}
/*
Creating object in java
Car car = new CAr();
*/
//creating object in javaScript outside the body of the class
letcar=newCar("Toyota",'Camry',2022,"White");
letbike=newCar("Honda","cvr",2023,"red");
car.drive();
bike.break();
console.log(car.add(10,15));
car.initializingVariableInsideMethod();