to create a object in js code example
Example 1: Build JavaScript Objects
var myDog = {
name: "gozi",
legs: 4,
tails: 1,
friends: ["Ted", "Fred"]
};
Example 2: 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 3: make an object javascript
class ObjectLayout {
constructor() {
this.firstName = "Larry";
}
sayHi() {
return `Hello from ${this.firstName}`;
}
}
const object = new ObjectLayout();
Example 4: how to create a object in javascript
var about = {
name:"lanitoman",
age:1023,
isHeProgrammer:true
}