Category: 02. Objects: The Basics
-
Javascript Constructor, operator “new”
The “new” operator allows creating an instance of a user-defined object type or a built-in operator type that has a constructor function. You can do the following things using the “new” keyword. You can create a blank object of JavaScript; Link this object to another one; Pass the freshly created object from Step 1 like this context; Get back this in case the function doesn’t return…
-
JavaScript Object to Primitive Conversion
Now it’s time to find out what will happen if you add objects obj1 + obj2, subtract obj1 – obj2, or print using alert(obj). In such a case, objects will be auto-converted to primitives, after which the operation will be carried out. Here are the main rules for numeric, string, and boolean conversions of objects: Overall objects are considered true in a boolean conversion.…
-
JavaScript Symbol Types
In general, object property keys can be of two types: string and symbol. Symbols are ultimately unique identifiers. They can be created by using the factory function Symbol(). For instance: After creating a symbol, you can give it a name or a description. It is especially useful for debugging practices. Let’s check out the following example: As we have…
-
JavaScript Garbage Collection
In this chapter, we are going to see how JavaScript manages its memory. JavaScript is a unique language, it is capable of automatically allocating memory once objects are created and freeing it when they are not used anymore. In contrast, low-level languages require manual determination at what point in the program that allocated memory is not needed…
-
JavaScript Object Methods, “this”
In JavaScript, objects are created for representing real-world entities, such as orders, users, and more. Here is an example: In the real world, you act like this: login, logout, choose something from a shopping cart, and more. In JavaScript, you can represent actions by functions in properties. Examples of Methods Your first step while studying JavaScript object…
-
Javascript Objects
Defining JavaScript Objects Properties and Literals Square Brackets Computed Properties Shorthand for Property Value The “for…in” loop Checking Existence Copy by Reference Comparing by Reference Const object Clone and Merge, Object.assign Defining JavaScript Objects Generally, JavaScript is known as an Object Oriented Programming language. Hence, in JavaScript, objects are the most important data types and forms. They…