How are objects created in arrays

In real life, a car is an object.A car has properties like weight and color, and methods like start and stop:car.name = Fiatcar.model = 500car.weight = 850kgcar.color = whitecar.start()car.drive()car.brake() car.stop()All cars have the same properties, but the property values differ from car to car. All cars have the same methods, but the methods are performed at different times.You have already learned that JavaScript variables are containers for data values. This code assigns a simple value (Fiat) to a variable named car: var car = "Fiat";Objects are variables too. But objects can contain many values.This code assigns many values (Fiat, 500, white) to a variable named car:var car = {type:"Fiat", model:"500", color:"white"};The values are written as name:value pairs (name and value separated by a colon).var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};Spaces and line breaks are not important. An object definition can span multiple lines:var person = { firstName: "John", lastName: "Doe",  age: 50,  eyeColor: "blue"};You can access object properties in two ways:objectName.propertyName or person.lastName;Below you can see a object being created and and a function being created which calls out the object's properties.var person = { firstName: "John", lastName : "Doe", id      : 5566, fullName : function() {    return this.firstName + " " + this.lastName;  }};

AA

Related Javascript Mentoring answers

All answers ▸

Make button that says how many times it has been clicked.


What is the difference between let and var when declaring variables in javascript?


What does the following code do and why? console.log(1+"2")


How do you create objects in javascript?