JavaScript is one of the scripting language that is mainly used in web applications. "Object" is one of the good concept which is used while coding with javascript.
Let me explain it with a suitable example:-
objectinitial.html :-
<html>
<head>
<script type="text/javascript">
ronny = {name:"Ronny Thomson", age:24};
shilpa = {name:"Shilpa Thomson", age:20};
</script>
</head>
<body>
<script type="text/javascript">
console.log(ronny.name + " loves " + shilpa.name + " as she is " + shilpa.age +" yrs old!");
</script>
</body>
</html>
Output:-
Explanation:-
Here, "ronny" & "shilpa" are objects initialized with particular data. "name" is the key of the object "ronny" and "Ronny Thomson" is the value of it. So, to display the value of the key - name, we need to use dot(.) operator, i.e, ronny.name.
No comments:
Post a Comment