Front End Technology Articles - Page 509 of 860

What is the use of OBJECT.assign() in javascript?

Ayush Gupta
Updated on 17-Sep-2019 08:55:08

290 Views

The Object.assign() method is used to copy the values of all of the object's own properties(enumerable only) from one or more source objects to a target object. It will return the target object.Exampleconst targetObj = { a: 1, b: 2 }; const sourceObj = { b: 4, c: 5 }; const returnedTarget = Object.assign(targetObj, sourceObj); console.log(targetObj); console.log(returnedTarget); console.log(returnedTarget === targetObj); console.log(sourceObj);Output{ a: 1, b: 4, c: 5 } { a: 1, b: 4, c: 5 } true { b: 4, c: 5 }Note −sourceObj did not change.returnedTarget and targetObj are the same.The Object.assign() method only copies enumerable and own properties from ... Read More

Async/Await Functions in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:52:12

967 Views

Handling asynchronous tasks is essential for network programming. In JavaScript most cases, we ask for data that are not synchronous to our system. To handle asynchronous systems, we can use Async and Await functions in JavaScript. The async keyword which is used with a function will qualify a javascript function as an asynchronous function. Async Function The async functions are very similar to the normal functions in javascript. The syntax is like below− From the syntax, it is clear that only the ‘async’ keyword is added to the function signature. Syntax async function name(param1, param2, ...paramN) { ... Read More

Multiple inheritance in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:39:00

6K+ Views

JavaScript is a partially object-oriented language. To work with this, the object-oriented nature needs to be understood. In this article, we are going to focus on the multiple inheritance concept inside JavaScript. An object can be inherited from multiple other objects, i.e. the object has common property from other parent objects not only a single parent. In JavaScript, this can be achieved by merging properties from different properties into one single object. Let us see the overall syntax which represents how multiple properties can be merged. SyntaxLet us consider a function syntax like the below − function multiple(...arguments) { ... Read More

Method Chaining in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:34:35

8K+ Views

Method or function chaining is a popular method in JavaScript that is used to write more concise and readable code. In this article, we shall discuss the method of chaining tactics in JavaScript and also discuss how it works In some JavaScript programs written with JQuery or some other packages, sometimes we call multiple functions one after another on the same line. This can be explained by a simple example as shown below − Syntax ob = ob.method_1().method_2().(some more methods).method_n() Example Without using the method of chaining. HTML Console ... Read More

Example of a circular reference in Javascript

Arnab Chakraborty
Updated on 05-Apr-2023 12:17:28

2K+ Views

Circular referencing is an idea when an object directly or indirectly refers to itself back. It creates a closed loop. Like other programming languages, javascript also faces this problem of circular referencing. In this article, we shall cover a few examples of different circular referencing modes in javascript. Direct Circular Referencing In direct circular referencing the object is pointing itself by using the self pointer. In this example, we can expand the user object infinitely (in practice up to a certain limit) and all are pointing to the same object. Let us see the following code and the output console ... Read More

Eradicating Memory Leaks in Javascript

Ayush Gupta
Updated on 17-Sep-2019 08:15:58

192 Views

The main cause for leaks in garbage collected languages are unwanted references. To understand memory leaks, let us see how the memory freeing(garbage collection) works.Mark-and-sweep algorithm −This algorithm reduces the definition of "an object is no longer needed" to "an object is unreachable". This algorithm assumes the knowledge of a set of objects called roots. In JavaScript, the root is the global object. Periodically, the GC starts from these roots, find all objects that are referenced from these roots, recursively. Starting from the roots, the GC will thus find all reachable objects and collect all non-reachable objects.Types of memory leaks1. ... Read More

HTML href Attribute

AmitDiwan
Updated on 17-Sep-2019 08:14:27

356 Views

The href attribute is used to set the link i.e. the URL of the page.SyntaxFollowing is the syntax −Above, URL is the url you need to mention, which can be a relative link, absolute link, script, protocol, etc.ExampleLet us now see an example to implement the href attribute of the element − Live Demo Learning is Fun Learn the concepts of Java! Also try JavaScript from our website: JavaScript! OutputThis will produce the following output −ExampleLet us see another example wherein we can set the email-id of a user with a href − Live ... Read More

Practical Uses for Closures in Javascript?

Arnab Chakraborty
Updated on 22-Aug-2022 13:55:39

732 Views

In JavaScript, the closure is an environment which helps us to access an outer function’s scope from an inner function. In JavaScript, when a function is created, the closure also created. In other words, we can say closure is a way which allows functions that is present inside outer functions to access the outer function’s scope. In this article we are focusing on some practical uses of Closures in JavaScript. Syntax function outerFunction(){ function updateProperty(){ } return updateProperty() } ... Read More

How to avoid circular reference in OOP Javascript?

Ayush Gupta
Updated on 17-Sep-2019 08:05:54

496 Views

A circular reference occurs if two separate objects pass references to each other.In older browsers circular references were a cause of memory leaks. With improvements in Garbage collection algorithms, which can now handle cycles and cyclic dependencies fine, this is no longer an issue.However, from a pure design point of view, circular referencing is still a bad thing and a code smell. Circular referencing implies that the 2 objects referencing each other are tightly coupled and changes to one object may need changes in other as well.Avoiding circular referencesThere is no one way to avoid circular reference in JS. It ... Read More

Why circular reference is bad in javascript?

Ayush Gupta
Updated on 17-Sep-2019 08:02:47

1K+ Views

A circular reference occurs if two separate objects pass references to each other.In older browsers circular references were a cause of memory leaks. With improvements in Garbage collection algorithms, which can now handle cycles and cyclic dependencies fine, this is no longer an issue.However, from a pure design point of view, circular referencing is still a bad thing and a code smell. Circular referencing implies that the 2 objects referencing each other are tightly coupled and changes to one object may need changes in other as well.Avoiding circular referencesThere is no one way to avoid circular reference in JS. It ... Read More

Advertisements