---
title: "Explain the JavaScript object"  
description: "here you will learn about all types of javascript objects and it's functionality."  
author: "Ashutosh Patel"  
published: 2025-02-14  
updated: 2025-02-14  
canonical: https://www.mindstick.com/articles/338542/explain-the-javascript-object  
category: "javascript"  
tags: ["javascript", "javascript object", "javascript method"]  
reading_time: 3 minutes  

---

# Explain the JavaScript object

Object in JavaScript is a [collection](https://www.mindstick.com/interview/2199/what-is-the-collections-api-in-java) of `key-value` pairs. It is used to store [multiple values](https://www.mindstick.com/forum/399/how-to-insert-multiple-values-selected-in-checkbox-in-database) ​​in a [structured](https://yourviews.mindstick.com/view/88498/underbust-corset-styling-guide-for-structured-everyday-looks) manner.

## Syntax:

```plaintext
let objectName = {
   key1: value1,
   key2: value2,
   key3: value3
};
```

- **Key** → Property name (string)
- **Value** → Can be string, number, boolean, array, [function](https://yourviews.mindstick.com/story/1308/four-types-of-human-teeth-amp-their-function), or any other object.

#### Creating an Object

## Using Object Literal (Most Common)

```javascript
let person = {
   name: "John",
   age: 30,
   city: "New York"
};
console.log(person);  // { name: "John", age: 30, city: "New York" }
```

## Accessing Object [Properties](https://www.mindstick.com/blog/673/properties)

- **Using [Dot Notation](https://www.mindstick.com/forum/33387/performance-difference-between-dot-notation-versus-method-call-in-objective-c) (**`.`**)**

```javascript
console.log(person.name);  // "John"
console.log(person.age);   // 30
```

- **Using Bracket Notation (**`[]`**)**

```javascript
console.log(person["name"]);  // "John"
console.log(person["age"]);   // 30
```

**Use bracket notation** when property names have **spaces or special [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters)**

```javascript
let obj = { "first name": "John" };
console.log(obj["first name"]);  // "John"
```

#### Adding & Updating Properties

## Adding a New Property

```javascript
person.country = "USA";
console.log(person.country);  // "USA"
```

## Updating an Existing Property

```javascript
person.age = 35;
console.log(person.age);  // 35
```

#### Deleting a Property

```javascript
delete person.city;
console.log(person.city);  // undefined
```

#### Checking if a Property Exists

**Using** `in` **[Operator](https://www.mindstick.com/interview/1098/what-is-the-difference-between-the-and-operators)**

```javascript
console.log("age" in person);  // true
console.log("city" in person); // false
```

**Using** `hasOwnProperty()`

```javascript
console.log(person.hasOwnProperty("name"));  // true
console.log(person.hasOwnProperty("city"));  // false
```

#### Looping Through an Object

**Using** `for...in` **loop**

```javascript
for (let key in person) {
   console.log(key + ": " + person[key]);
}
```

## Output:

```plaintext
name: John
age: 35
country: USA
```

####

#### Nested Objects

Objects can also contain other objects.

```javascript
let student = {
   name: "Alice",
   marks: {
       math: 90,
       science: 85
   }
};
console.log(student.marks.math);  // 90
console.log(student["marks"]["science"]);  // 85
```

#### Object Methods (Functions Inside Objects)

An object method is a function that is stored inside an object.

```javascript
let car = {
   brand: "Toyota",
   model: "Corolla",
   start: function() {
       return "Car started";
   }
};
console.log(car.start());  // "Car started"
```

#### `this` Keyword in Objects

`this` refers to the current object.

```javascript
let user = {
   name: "Alex",
   greet: function() {
       return "Hello, " + this.name;
   }
};
console.log(user.greet());  // "Hello, Alex"
```

#### Creating Objects Using `new Object()`

```javascript
let car = new Object();
car.brand = "Ford";
car.model = "Mustang";
console.log(car.brand);  // "Ford"
```

## Summary

- Objects store data as key-value pairs.
- Methods are [functions](https://www.mindstick.com/forum/161928/explain-the-python-functions-with-explanation) inside the object.
- Use the dot (.) or bracket ([]) notation to access properties.
- Use a for...in loop to iterate over the object.
- Use this to refer to the current object.

I hope you understand clearly the javascript objects.

Thanks.

**Also, read:** [JavaScript Loops Explanation](https://www.mindstick.com/articles/338540/javascript-loops-explanation)

---

Original Source: https://www.mindstick.com/articles/338542/explain-the-javascript-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
