MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

JavaScript Tutorial

Objects In JavaScript
Previous Home Next

JavaScript is not really an object oriented language, it is a prototyping language An object is a collection of properties

There are defferent way to use object in javascript .

  • using object literal
  • using instance of Object i.e new keyword
  • using an object constructor i.e using this keyword

using object literal

Syntax :

object={method1:value1,method2:value2.....methodN:valueN}  

Example :

<html>
<body>
<script>  
emp={id:"A-38 ",name:"rajesh Kumar",salary:50000}  
document.write(emp.id+" "+emp.name+" "+emp.salary);  
</script>
</body>
</html>

Output :

A-38 rajesh Kumar 50000

 

using instance of Object

Here new keyword is used to create an object

Syntax :

 var objectname=new Object();  

Example :

<html>
<body>
<script>
var book = new Object();
book.id = 121;
book.name = "java";
book.rate = 1000;
document.write(book.id+" "+book.name+" "+book.rate);
</script>
</body>
</html>

Output :

121 java 1000

object constructor i.e using this keyword

Here, used this keyword to show the Object method .

Example :

<html>
<body>
<script>  
function book(id,name,rate)
{  
this.id=id;  
this.name=name;  
this.rate= rate;  
}
b=new book (121,"core java",500);  
document.write(b.id+" "+b.name+" "+b.rate);  
</script>  
</body>
</html>

Output :

121 core java 500

Previous Home Next