Skip to content

Commit a397ec8

Browse files
committed
accessing object using its property
1 parent 9eef64e commit a397ec8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

JavaScript Function or Getter.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
<h2>JavaScript Object Method</h2>
7+
8+
<p>Object data can be accessed using property stored as a function.</p>
9+
10+
<p id="demo"></p>
11+
12+
<script>
13+
// Create an object:
14+
var person = {
15+
firstName: "Sanu",
16+
lastName: "santh",
17+
fullName: function () {
18+
return this.firstName + " " + this.lastName;
19+
}
20+
};
21+
// Display data from the object using a method:
22+
document.getElementById("demo").innerHTML = person.fullName();
23+
</script>
24+
25+
</body>
26+
27+
</html>

0 commit comments

Comments
 (0)