Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create an object in JavaScript

    • 0
    • 4
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 599
    Comment on it

    Hello all,

    In JavaScript we can create objects in many ways, some of them are listed below:

    1. We can create objects by using new keyword and we can assign a value to the object while creating in or we can also set the various properties of that object which can be accessed later on by putting dot after the object name it self.

      Ex. (1)

      var obj = new Object("myObj");
      Ex. (2)

      var obj = new Object();
       obj.name = 'Gaurav';
       obj.work= 'Study';
       obj.subject= 'Computer Science';
      
    2. We can also create Objects with an object literal such as :

       var house= {type:"Duplex", area:"500", Height:"600"};

    3. We can also create Objects like a function such as :

      var obj = function () {
          name:'Gaurav';
          work: 'study';
          subject: 'Computer Science';
      }
      

      or

      function employee(name, emailId, contactNo) {
          this.fullName= name;
          this.email= emailId;
          this.contact= contactNo;
      }
      var employee1= new employee("Mark wood", "mk@xyz.com", "123456");
      var employee2= new employee("Joy Root", "jr@xyz.com", "789012");
      

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: