Shefali Profile picture
✍️Passionate about Simplifying Tech 📩DM for collab ➡️https://t.co/GRrKB3rjti ➡️https://t.co/fJI2jIeNQP ➡️https://t.co/qy8Lw4Skbr

Jul 3, 2024, 24 tweets

JavaScript Objects🔥

Open this🧵

💠Creating Objects

You can create objects in the following ways:

1⃣Object Literal

You can create an object using object literal i.e., curly braces.

2⃣Constructor Function

Using the 'new' keyword, the constructor function allows the creation of multiple objects.

3⃣Factory Function

Factory functions are functions that return objects.

You can create objects using factory functions.

4⃣Object.create()

Using Object.create() method, you can create a new object using an existing object as the prototype for the newly created object.

5⃣ES6 Class Syntax

You can use the 'class' keyword to define a constructor and methods for objects.

💠Object Properties Methods

1⃣Accessing Properties

You can access the properties of an object using dot notation or square brackets.

2⃣Modifying Properties

Objects are mutable, so you can modify the value of a property by assigning a new value to it.

3⃣Adding Properties

You can add new properties to an object as follows.

4⃣Checking the Presence of a Property

You can check if an object has a specific property using the following methods.

🔹hasOwnProperty method

🔹in operator

5⃣Deleting Properties

You can use the 'delete' operator to remove a property from an object.

6⃣Object.freeze()

You can use Object.freeze() method to prevent any changes to an object, including adding, modifying or deleting properties.

7⃣Object.seal()

You can use Object.seal() method to prevent adding or removing properties in the object.

8⃣Looping through Properties

You can loop through an object's properties using the following methods.

🔹for...in loop

🔹Object.keys

This method returns the array of keys of an object.

🔹Object.values

This method returns the array of values of an object.

🔹Object.entries

This method returns the array of key-value pairs of an object.

💠Nested Objects

If you create an object, in which, an object is used as a value of the object, then this refers to a nested object.

This is used for organizing and structuring complex data hierarchies.

💠Object Destructuring

Object destructuring in JavaScript is a way to extract specific properties from an object and assign them to variables.

It's a handy shortcut that lets you access object properties without typing out long dot notation every time.

💠Object Spread Operator

If you want to create an object by copying the properties of an existing object and adding or modifying properties as needed, then you can use the spread '...' operator.

You can read the full article here👇
shefali.dev/javascript-obj…

That's a wrap.

Thanks for checking out.

If you find this thread helpful, then consider:
❤️Like
✅Follow me @Shefali__J for more content like this.
🔁Repost the below quote 👇

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling