ways to create object in javascript code example

Example 1: Build JavaScript Objects

var myDog = {
  name: "gozi",
  legs: 4,
  tails: 1,
  friends: ["Ted", "Fred"]
};

Example 2: creating an object javascript

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

Example 3: objects in javascript

let object = {
  'key1': 'value1',
  'key2': 'value2',
  'keyn': 'valuen',
};
console.log(object);

Example 4: objects in javascript

let car = {
  engineNumber: 1234
  brand: 'BMW',
  break: function (){}
}

Example 5: how to create object js

function person(fname, lname, age, eyecolor){
  this.firstname = fname;
  this.lastname = lname;
  this.age = age;
  this.eyecolor = eyecolor;
}

myFather = new person("John", "Doe", 50, "blue");
document.write(myFather.firstname + " is " + myFather.age + " years old.");

Example 6: js create new object

let bike = {   name: 'SuperSport',    maker:'Ducati',    start: function() {       console.log('Starting the engine...');   }};bike.start();   //Output: Starting the engine.../* Adding method stop() later to the object */bike.stop = function() {    console.log('Applying Brake...');  }bike.stop();    //Output: Applying Brake...