js object literal code example
Example 1: javascript object
var person = {
first_name : "Marty",
last_name : "Mcfly",
born : 1968,
died : 1933,
lovers: ["Jennifer Parker","Baines McFly"]
};
Example 2: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 3: 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 4: object literal javascript
var myObject = {
sProp: 'some string value',
numProp: 2,
bProp: false
};
Example 5: how to create a object in javascript
var about = {
name:"lanitoman",
age:1023,
isHeProgrammer:true
}
Example 6: literal object js
var car = {type:"Fiat", model:"500", color:"white"};