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.
CSS-Tricks is one of the best resources for learning CSS. It was created by web designer Chris Coyier and is filled with tutorials, tips, and guides that help developers at any skill level. css-tricks.com
🎯CSSnippets
CSSnippets is a collection of useful code snippets for HTML, React, CSS, and Tailwind CSS. It has ready-made code for things like buttons, box-shadows, cards, checkboxes, dropdowns, and more. Developers can quickly copy these snippets. cssnippets.shefali.dev
‘this’ in JavaScript: 10 Scenarios Simplified for Beginners🔥
Open this🧵
What is “this”?
In JavaScript, “this” is a special keyword that refers to the current execution context which means what is happening right now.
It changes its value depending on how a function is invoked.
So, let’s explore its different scenarios.
1⃣“this” in Global Context
When we use “this” in the global scope, then “this” refers to the global object.
For example, when we use “this” in a browser environment, then this is often the window object.
Now, what is window object?🤔
The window object represents that browser window which contains the document. This object provides properties and methods, by using them you can interact with the browser environment.