defining objects in javascript code example
Example 1: how to create object in javascript with class
let myCar1 = new Car("Ford", 2014);
let myCar2 = new Car("Audi", 2019);
Example 2: objects in javascript
let object = {
'key1': 'value1',
'key2': 'value2',
'keyn': 'valuen',
};
console.log(object);
Example 3: objects in javascript
let car = {
engineNumber: 1234
brand: 'BMW',
break: function (){}
}
Example 4: object literal javascript
var myObject = {
sProp: 'some string value',
numProp: 2,
bProp: false
};
Example 5: make an object javascript
class ObjectLayout {
constructor() {
this.firstName = "Larry";
}
sayHi() {
return `Hello from ${this.firstName}`;
}
}
const object = new ObjectLayout();