objects javascript example

Example 1: creating an object javascript

let obj = {
// fields
  name:"value",
  num: 123,
//methods
  foo: function(){}
  
}

Example 2: how to create object in javascript with class

let myCar1 = new Car("Ford", 2014);

let myCar2 = new Car("Audi", 2019);

Example 3: how to create object in javascript with class

class Car {

   constructor(name, year) {

    this.name = name;

    this.year = year;

  }

}

Example 4: objects javascript

function Dog() {
  this.name = "Bailey"; 
  this.colour = "Golden"; 
  this.breed = "Golden Retriever";
  this.age = 8;
}

Tags:

Java Example