x
1
2
<html>
3
<body>
4
5
<h2>JavaScript Class</h2>
6
7
<p>How to use a JavaScript Class.</p>
8
9
<p id="demo"></p>
10
11
<script>
12
class Car {
13
constructor(name, year) {
14
this.name = name;
15
this.year = year;
16
}
17
}
18
19
const myCar = new Car("Ford", 2014);
20
document.getElementById("demo").innerHTML =
21
myCar.name + " " + myCar.year;
22
</script>
23
24
</body>
25
</html>
JavaScript Class
How to use a JavaScript Class.
Ford 2014