JavaScript Asynchronous Functions Overview
In JavaScript, asynchronous functions help us execute tasks without blocking the main program flow.Instead of waiting for one task to finish, JavaScript moves ahead and handles results later.These functions are mainly used for timers, API calls, and background operations, making web applications faster and more responsive. Below are some important asynchronous functions like setTimeout, setInterval, Promises, async/await, and fetch, with examples and use cases.

Javascript Objects
An object in JavaScript is basically a dynamic data structure. It stores related data in the form of key-value pairs, where each key acts as a unique identifier for its value.Inside an object, the values can be different types like primitive values such as numbers and strings, or even other objects, and also functions. When a function is written inside an object, we call it a method.One important point is that objects are mutable, meaning we can change them anytime. We can add new properties, modify existing ones, or even delete properties after the object is created.Objects are mainly used because they help in grouping related data and behavior together. So instead of storing everything separately, we can keep all related information in one place, which makes the code more organized and easier to manage.
There are two primary ways to create an object in JavaScript:
1. Creation Using Object Literal
The object literal syntax allows you to define and initialize an object with curly braces {}, setting properties as key-value pairs.
let obj = {
name: "EzhilAnban",
age: 23,
job: "Developer"
};
console.log(obj);//{"name":"EzhilAnban","age":30,"job":"Developer"}
2. Creation Using new Object() Constructor
let obj = new Object();
obj.name= "EzhilAnban"",
obj.age= 23,
obj.job= "Developer"
console.log(obj);//{"name":"EzhilAnban"","age":30,"job":"Developer"}
Basic Operations on JavaScript Objects
1. Accessing Object Properties
You can access an object’s properties using either dot notation or bracket notation.
const airpods = {
brand: "Apple",
model: "AirPods Pro",
price: 24900
};
// accessing properties
console.log(airpods.brand); // Apple
console.log(airpods.model); // AirPods Pro
console.log(airpods.price); // 24900
2. Modifying Object Properties
Properties in an object can be modified by reassigning their values.
const airpods = {
brand: "Apple",
model: "AirPods Pro",
price: 24900
};
airpods.price = 22900; // updated price
console.log(airpods.price);//22900
3. Adding Properties to an Object
You can dynamically add new properties to an object using dot or bracket notation.
airpods.color = "White";
console.log(airpods.color);
4. Removing Properties from an Object
The delete operator removes properties from an object.
const airpods = {
brand: "Apple",
model: "AirPods Pro",
price: 24900
};
// delete a property
delete airpods.price;
console.log(airpods);//{"brand":"Apple","model":"AirPods Pro"}
5. Merging Objects
Objects can be merged using Object.assign() or the spread syntax { ...obj1, ...obj2 }.
const obj1 = {
brand: "Apple",
model: "AirPods Pro"
};
const obj2 = {
price: 24900,
color: "White"
};
const merged = { ...obj1, ...obj2 };
console.log(merged);
//{
brand: "Apple",
model: "AirPods Pro",
price: 24900,
color: "White"
}
Using Object.assign()
const obj1 = { brand: "Apple" };
const obj2 = { model: "AirPods Pro" };
const merged = Object.assign({}, obj1, obj2);
console.log(merged);
//{ brand: 'Apple', model: 'AirPods Pro' }
6. Object Length
You can find the number of properties in an object using Object.keys().
const airpods = {
brand: "Apple",
model: "AirPods Pro",
price: 24900
};
console.log(Object.keys(airpods).length);//3
References
https://www.geeksforgeeks.org/javascript/objects-in-javascript/
Top comments (0)