create a new object in javascript code example
Example 1: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 2: make an object javascript
class ObjectLayout {
constructor() {
this.firstName = "Larry";
}
sayHi() {
return `Hello from ${this.firstName}`;
}
}
const object = new ObjectLayout();
Example 3: how to create a object in javascript
var a = {
name: "aakash",
age:30
}
Example 4: how to create a object in javascript
var about = {
name:"lanitoman",
age:1023,
isHeProgrammer:true
}
Example 5: create object javascript
let voleur = {
action : () =>console.log ('Coup de dague fatal') ,
crie : ('pour la horde!!!!') ,
coupfatal :()=> console.log ('coup dans le dos')
}
voleur.action() ;
voleur.coupfatal() ;
console.log(voleur.crie) ;
Example 6: how to create an object in javascript
const person = {
name: 'Anthony',
age: 32,
city: 'Los Angeles',
occupation: 'Software Developer',
skills: ['React','JavaScript','HTML','CSS']
};
const message = `Hi, I'm ${person.name}. I live in ${person.city}.`;
console.log(message);