1) With keyword
new
:
var car = new Object();
car.model = "Honda Fit";
car.year = 2004;
car.color = "Blue";
2)Using an Object Literal
var car = {model :"Honda Fit", year :"2004", color:Blue};
3)
var car = {};
car.model = "Honda Fit";
car.year = 2004;
car.color = "Blue";
4) Using the Object.create method
var animal1 = Object.create(Animal);
animal1.displayType(); // Output:Invertebrates
5)Using a constructor function
Define the constructor function.
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
then create an object called mycar:
var mycar = new Car('Honda', 'Fit', 2004);