Mindblown: a blog about philosophy.
-
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…
-
JavaScript Arrow Functions
Arrow functions are one of the popular features of ES6 syntax for writing JavaScript function expressions. Arrow function expressions cannot be used as constructors. Arrow functions also called “fat arrow” functions, there are a more concise syntax for writing function expressions. By using arrow functions, we avoid having to type the function keyword, return keyword and curly brackets. This creates a function func…
-
JavaScript Function Expressions
There are two different ways of creating functions in JavaScript. We can use function declaration and function expression. The difference between them is the function name, which can be omitted in function expressions to create anonymous functions. Here is the syntax for Function Declaration: And this is the syntax for Function Expression: The function is assigned to the variable, like any other value. No matter…
-
JavaScript Functions
Like every programming language, JavaScript also supports the use of functions. JavaScript functions are the main blocks of code designed to perform a particular task. Functions allow the code to be called many times without repetition. Function Declaration We can create functions in JavaScript using a function declaration that looks like this: As you see in the…
-
JavaScript Loops: while and for
While writing a program, you can meet a situation when you need to execute an action repeatedly. In that case, you would need to write loop statements, which let us reduce the number of lines. In other words, loops offer a quick and easy way to do something repeatedly. For example, if you want to type…
Got any book recommendations?