JavaScript Objects

JavaScript Tutorial

JavaScript Objects

In JavaScript, an object is a collection of related data stored in key-value pairs. Keys are call properties, and values can be strings, numbers, arrays, functions, or even other objects.

Objects help organize data in a structured way.


Creating an Object


Accessing Object Properties

You can access properties in two ways:

1. Dot Notation

2. Bracket Notation


 Adding & Updating Properties


Deleting a Property


Objects with Methods

A method is a function inside an object.


 

Output:

Car is starting...

Nested Objects

Objects can contain other objects.


 


Looping Through an Object

Use for...in loop:


 


Object Constructor


 


Summary

FeatureDescription
Store multiple valuesUsing key-value pairs
Access valuesDot . or bracket []
Can have functionsCalled methods
Can be nestedObject inside object

JavaScript objects are the foundation of modern JavaScript programming and are heavily use in frameworks like React, Node.js, and APIs.

You may also like...