JavaScript Program to Create an Object and display its properties

Write a JavaScript program to create an object and display its properties.

Source Code

  <title> for... in example </title>
<script language="javascript" type="text/javascript">
  var book = new Object(); // object creation
  // properties and values of book
  book = { title:"Let Us C",
    author:"Yashvant Kanetkar", 
    publisher: "BPB Publications", 
    price: "Rs 399/-" 
  var result = "";
  // name of distinct property of book assign to b in each loop execution
  for (var b in book)
    // book[b] is used to get the values.
    result += "book." + b + " = " + book[b] + "<br>";
  // to print names and values of each property of book object.

"Coding Hub - Learn to code" app now available on Google Play Store