Objects in JavaScript

Published: (December 17, 2025 at 09:44 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

What is Objects?

  • An object is a variable that can hold multiple variables.
  • It is a collection of key‑value pairs, where each key has a value.
  • Combination of states (attributes) and behavior (methods).
  • Declare an object with the const keyword.

Example

const person = {
  name: "Jack",
  age: 41,
  city: "New York"
};
console.log(person.name);

Adding New Attributes

Example

const person = {
  name: "Jack",
  age: 41,
};

person.city = "New York"; // Add attribute
console.log(person.city);

Deleting Existing Attributes

  • The delete keyword removes a property from an object.

Example

const person = {
  name: "Jack",
  age: 41,
  city: "New York"
};

delete person.city; // Delete attribute
console.log(person);

Updating Attributes

  • Assign a new value to the same key (same syntax as adding).

Example

const person = {
  name: "Jack",
  age: 41,
  city: "New York"
};

person.age = 42;
console.log(person.age);
Back to Blog

Related posts

Read more »

Build Your Own React

Article URL: https://pomb.us/build-your-own-react/ Comments URL: https://news.ycombinator.com/item?id=46332526 Points: 18 Comments: 3...