JavaScript
Objects
What is an object?
Objects are collections of key-value
pairs. They allow you to group
related data and functions, making
your code more organized and
easier to manage.
Think of objects as real-world entities
like a car or a person, with properties
and behaviors.
Creating Objects in
JavaScript:
Using an Object Literal
Using the new Keyword
Using an Object Constructor
Using an Object
Literal
An object literal is a list of
name:value pairs inside curly braces
{}.
let person { name: 'Ravi',
age: '23' }
Using the new
Keyword
const person = new
Object();
person.firstName = "Ravi";
person.age = 23;
Using an Object
Constructor
function person(name,
age) { this.name = name;
this.age= age; }
Accessing Object
Properties
Dot Notation: car.make
Bracket Notation: car['make']
Example
person.name;
person["name"];
Thanks For
Reading