Category: 2. 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. The {…} syntax lets developers create a single object. But, sometimes, it is necessary to generate many similar objects such as menu items, multiple users, and more. You can do it using…

  • 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: ToPrimitive It is possible to enhance string and numeric conversion. To…

  • 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 Generally, JavaScript is known as an Object Oriented Programming language. Hence, in JavaScript, objects are the most important data types and forms. They are entirely different from primitive data types in JavaScript. As it was mentioned in the the chapter “Data types”, there are seven data types in JavaScript, six of which are called “primitive” as their values include…