make an object javascript code example

Example 1: objects in javascript

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

Example 2: objects in javascript

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

Example 3: objects javascript

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

Example 4: create object javascript

const object = {
  something: "something";
}

Example 5: make an object javascript

class ObjectLayout {
	constructor() {
    	this.firstName = "Larry"; //property
    }
  
  	sayHi() { // Method
    	return `Hello from ${this.firstName}`;
    }
}

const object = new ObjectLayout();
// object.firstName is Larry;
// object.sayHi() gives "Hello from Larry"

Example 6: objects in javascript

let name = {
	name1: 'mark'
}

Tags: