<html>
<head>
<title>Javascript Object literal</title>
</head>
<body>
<script type="text/javascript">
emp={id:9, name:"Ramana Reddy", salary:36000}
//Display Multiple Line
document.write("Emp ID : " + emp.id + "<br />");
document.write("Emp Name : " + emp.name + "<br />");
document.write("Emp Salary: " + emp.salary + "<br /><br />");
//Display Single Line
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
</body>
</html>
Emp ID : 9
Emp Name : Ramana Reddy
Emp Salary: 36000
9 Ramana Reddy 36000
<html>
<head>
<title>Javascript Instance of Object</title>
</head>
<body>
<script type="text/javascript">
var emp=new Object();
emp.id=27;
emp.name="V V Ramana Reddy";
emp.salary=900000;
//Display Multiple Line
document.write("Emp ID : " + emp.id + "<br />");
document.write("Emp Name : " + emp.name + "<br />");
document.write("Emp Salary: " + emp.salary + "<br /><br />");
//Display Single Line
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
</body>
</html>
Emp ID : 27
Emp Name : V V Ramana Reddy
Emp Salary: 90000
27 V V Ramana Reddy 90000
<html>
<head>
<title>Javascript Object constructor</title>
</head>
<body>
<script type="text/javascript">
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
my_emp=new emp(36,"V V R Reddy",180000);
//Display Multiple Line
document.write("Emp ID : " + my_emp.id + "<br />");
document.write("Emp Name : " + my_emp.name + "<br />");
document.write("Emp Salary: " + my_emp.salary + "<br /><br />");
//Display Single Line
document.write(my_emp.id+" "+my_emp.name+" "+my_emp.salary);
</script>
</body>
</html>
Emp ID : 36
Emp Name : V V R Reddy
Emp Salary: 180000
36 V V R Reddy 180000
<html>
<head>
<title>Javascript Object Methods</title>
<script type="text/javascript">
// Define a function which will work as a method
function addPrice(amount){
this.price = amount;
}
function book(book_name, author){
this.book_name = book_name;
this.author = author;
this.addPrice = addPrice; // Assign that method as property.
}
</script>
</head>
<body>
<script type="text/javascript">
var myBook = new book("JavaScript", "V V Raamana Reddy");
myBook.addPrice(150);
document.write("Book Name is : " + myBook.book_name + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price + "<br>");
</script>
</body>
</html>
Book Name is : JavaScript
Book author is : V V Raamana Reddy
Book price is : 150