Create Object in JS

How many ways to create objects
There are many ways to create object in javascript
  • Object Literal
                        
                          var mobile = {};
                          mobile['model'] = 'Samsung Galaxy';
                        
                      
  • Object Literal declaration and initialization
                        
                          var mobile = {
                            name: 'Samung',
                            model: 'Galaxy'
                          };
                        
                      
  • Object Constructor
                        
                          var Mobile = new Object();
                        
                      
  • Factory Function
                        
                         function mobile () {
                            return {
                               model : 'Galaxy';
                            }
                         }
                         var samsung = mobile();
                        
                      
  • Constructor Function
                        
                          function Mobile () {
                            this.model = 'Galaxy',
                            this.price = 12000,
                          }
                          var samsung = new Mobile();
                          console.log(samsung.model);
                          //Function expression 
                          var Mobile =  function() { //We consider "Mobile" as a class 
                              this.model = 'Galaxy',
                              this.price = 12000,
                          }
                          var samsung = new Mobile();
                          console.log(samsung.model);