how many ways to create object in javascript code example
Example 1: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 2: objects in javascript
let object = {
'key1': 'value1',
'key2': 'value2',
'keyn': 'valuen',
};
console.log(object);
Example 3: objects in javascript
var object = {'key':'value','the value can be anything',[1,null,'Dr.Hippo']};
Example 4: make an object javascript
class ObjectLayout {
constructor() {
this.firstName = "Larry";
}
sayHi() {
return `Hello from ${this.firstName}`;
}
}
const object = new ObjectLayout();
Example 5: how to create a object in javascript
var about = {
name:"lanitoman",
age:1023,
isHeProgrammer:true
}
Example 6: js create new object
let bike = { name: 'SuperSport', maker:'Ducati', start: function() { console.log('Starting the engine...'); }};bike.start();