Object in Javascript with example

Object in Javascript with example

Access the properties of an object in javascript

<html> 
<head>
<title>javascript example</title>
</head>
<body>
<p>Below paragraph includes the name and age of the boy</p>
<p id="obj" style="font-weight: bolder;"></p>
<script>
const boy = {
first_name: "Robin",
last_name: "Sinha",
age: 23,
};
document.getElementById("obj").innerHTML = "The name of the boy is "+boy.first_name+" and age is "+boy.age;
</script>
</body>
</html>
<html> 
<head>
<title>Javascript example</title>
</head>
<body>
<p>Full name of the boy is</p>
<p id="fullname"></p>
<script>
const boy = {
first_name: "Robin",
last_name: "Sinha",
age: 23,
full_name: function(){
return this.first_name+" "+this.last_name;
}
};
document.getElementById("fullname").innerHTML = boy.full_name(); </script>
</body>
</html>

--

--

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bipsmedium

Bipsmedium

25 Followers

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.