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
Answered by Aminoor A. Javascript tutor

792 Views

See similar Javascript Mentoring tutors

Related Javascript Mentoring answers

All answers ▸

How would you change the background colour of a div with the id "colourme" to purple?


What is the importance of javascript in the web?


What does the document.onload() function do and why is it useful?


How do you create objects in javascript?


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences