JavaScript Objects🔥 Open this🧵

@Shefali__J
Shefali@Shefali__J
46 views Dec 06, 2024 ~2 min read
Advertisement
1
JavaScript Objects🔥

Open this🧵
Media image
2
💠Creating Objects

You can create objects in the following ways:
3
1⃣Object Literal

You can create an object using object literal i.e., curly braces.
Media image
4
2⃣Constructor Function

Using the 'new' keyword, the constructor function allows the creation of multiple objects.
Media image
5
3⃣Factory Function

Factory functions are functions that return objects.

You can create objects using factory functions.
Media image
6
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.
Media image
7
5⃣ES6 Class Syntax

You can use the 'class' keyword to define a constructor and methods for objects.
Media image
8
💠Object Properties Methods

1⃣Accessing Properties

You can access the properties of an object using dot notation or square brackets.
Media image
9
2⃣Modifying Properties

Objects are mutable, so you can modify the value of a property by assigning a new value to it.
Media image
10
3⃣Adding Properties

You can add new properties to an object as follows.
Media image
11
4⃣Checking the Presence of a Property

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

🔹hasOwnProperty method
Media image
12
🔹in operator
Media image
13
5⃣Deleting Properties

You can use the 'delete' operator to remove a property from an object.
Media image
14
6⃣Object.freeze()

You can use Object.freeze() method to prevent any changes to an object, including adding, modifying or deleting properties.
Media image
15
7⃣Object.seal()

You can use Object.seal() method to prevent adding or removing properties in the object.
Media image
16
8⃣Looping through Properties

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

🔹for...in loop
Media image
17
🔹Object.keys

This method returns the array of keys of an object.
Media image
18
🔹Object.values

This method returns the array of values of an object.
Media image
19
🔹Object.entries

This method returns the array of key-value pairs of an object.
Media image
20
💠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.
Media image
21
💠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.
Media image
22
💠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.
Media image
23
You can read the full article here👇
shefali.dev/javascript-obj…
24
That's a wrap.

Thanks for checking out.

If you find this helpful, then consider:
❤️Like
✅Follow me @Shefali__J for more content like this.
🔁Repost the below quote 👇
x.com/Shefali__J/sta…
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement