JavaScript Objects

What is an Object?

An object is a collection of key-value pairs.

It is used to store related data together.

Loading...
Output:

Accessing Properties

You can access values using dot or bracket notation.

Loading...
Output:

Modifying Objects

Loading...
Output:

Deleting Properties

Loading...
Output:

Nested Objects

Objects can contain other objects.

Loading...
Output:

Object Methods

Objects can contain functions called methods.

Loading...
Output:

The this Keyword

The this keyword refers to the current object.

Looping Through Objects

Loading...
Output:

Full Example

Loading...
Output:

Why Objects are Important

  • Store structured data
  • Used in APIs
  • Organize related data

Common Mistakes

  • Confusing arrays and objects
  • Using incorrect property access
  • Forgetting this in methods

Practice

Create an object for a book with title, author, and a method that prints details.

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic