Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a private variable in JavaScript?

Prerna Tiwari
Prerna Tiwari
Updated on 15-Mar-2026 6K+ Views

JavaScript doesn't have built-in private variables like other languages, but several techniques can simulate privacy. Each approach has its own benefits and use cases. Private variables can only be accessed and modified by code within the same scope, while public variables are accessible from anywhere. Let's explore different techniques to create private variables in JavaScript. Using Closures Closures are the most common way to create private variables. A closure allows inner functions to access variables from their outer function scope, even after the outer function has finished executing. ...

Read More

How to sort an array of objects based on the length of a nested array in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 3K+ Views

In JavaScript, you can sort an array of objects based on the length of nested arrays using the sort() method with a custom comparison function. This technique is useful when organizing data by array size. Understanding the Problem Consider an array of objects where each object contains a nested array property. To sort by nested array length, we need a comparison function that compares the length property of these nested arrays. Sorting by Nested Array Length Before Sorting ...

Read More

Finding the only even or the only odd number in a string of space separated numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 494 Views

We are required to write a JavaScript function that takes in a string that contains numbers separated by spaces. The string either contains all odd numbers and only one even number or all even numbers and only one odd number. Our function should return that one different number from the string. Problem Given a string of space-separated numbers where all numbers are either odd or even except for one, we need to find and return that unique number that differs from the rest. Example Following is the code: const str = '2 4 ...

Read More

Minimum deletion sum of characters in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 187 Views

The minimum deletion sum problem requires finding the lowest ASCII sum of characters that need to be deleted from two strings to make them equal. This is solved using dynamic programming to find the optimal sequence of deletions. Problem Statement Given two strings of lowercase English letters, we need to delete characters from both strings to make them identical, while minimizing the sum of ASCII values of deleted characters. Algorithm Approach We use dynamic programming where each cell dp[i][j] represents the minimum deletion cost to make substrings str1[i:] and str2[j:] equal. Example Input: ...

Read More

agent.createConnection() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 869 Views

The agent.createConnection() method is an interface provided by the Node.js http module. This method produces a socket/stream that can be used for HTTP requests. You can override this method in custom agents for greater flexibility. A socket/stream can be returned either directly from this function or by passing it to the callback. Syntax agent.createConnection(options, [callback]) Parameters The above function accepts the following parameters: options – These options contain the connection details for which the stream has to be created. ...

Read More

How to create a chart from JSON data using Fetch API in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 5K+ Views

In this article, we will explore how to create a chart after fetching JSON data using JavaScript's Fetch API. We'll first fetch the data from a remote server, then use that data to create a visual chart using Chart.js library. What is the Fetch API? The Fetch API provides a modern interface for making HTTP requests and handling responses. It returns promises, making it easier to work with asynchronous data compared to older methods like XMLHttpRequest. Syntax const response = fetch(resource [, init]) Parameters resource − The URL ...

Read More

How to set the background colour of selection of Rectangle using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 421 Views

In this tutorial, we are going to learn how to set the background colour of selection of a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. We can change an object's dimensions, rotate it or manipulate it when it is actively selected. We can change the background colour of selection of Rectangle by using the selectionBackgroundColor property. Syntax new fabric.Rect({ selectionBackgroundColor: String }: Object) Parameters ...

Read More

How to implement enqueue and dequeue using only two stacks in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we'll implement a queue using only two stacks. This is a common data structure interview question that demonstrates understanding of both queues (FIFO - First In, First Out) and stacks (LIFO - Last In, First Out). Algorithm STEP 1 − We have two stacks: one for enqueuing (input) and one for dequeuing (output). STEP 2 − We enqueue by pushing onto the enqueue stack. STEP 3 − We dequeue by popping from the dequeue stack. STEP 4 − ...

Read More

How to add subscript with Text using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 328 Views

In this tutorial, we are going to learn how to add subscript with Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also add subscripts by using the setSubscript method. Syntax setSubscript(start: Number, end: Number) Parameters start − This parameter ...

Read More

How does internationalization work in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 363 Views

In this article, you will understand how internationalization works in JavaScript. Internationalization is the process of preparing software so that it can support local languages and cultural settings. It can include changing the date and time format, changing the metric system format, language format, etc. JavaScript provides the Intl object which contains constructors for locale-sensitive formatting and language-sensitive string comparison. The most commonly used are Intl.DateTimeFormat for dates and Intl.NumberFormat for numbers. Date and Time Formatting Let's understand how to format dates for different locales using Intl.DateTimeFormat: var inputDate = new Date(1990, 2, 25); console.log("The ...

Read More
Showing 15481–15490 of 61,297 articles
Advertisements