Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a global Promise Rejection Handler in JavaScript?

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

Promise rejection handlers are a powerful tool in JavaScript for handling errors that occur in asynchronous code. In this article, we will learn how to build a global promise rejection handler in JavaScript and how it can help your application manage errors effectively. You can detect unhandled promise rejections using the global unhandledrejection event and take necessary action, such as logging errors to an error tracking service or displaying user notifications. A more understandable syntax for handling promise rejection is provided by async-await error handling, but it requires wrapping each async function in a try-catch block. Combining async-await with ...

Read More

Dynamic programming to check dynamic behavior of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 603 Views

We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length. The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end. For example: If the array is given by − const arr = ["c", "ca", "can", "acan", "acane", "dacane"]; Then our function should return true because: "ca" = "c" + "a" (adding "a" at the end) ...

Read More

Merge and group object properties in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 777 Views

In JavaScript, merging and grouping object properties is a common task when working with arrays of objects. This technique allows you to combine objects that share a common property (like a name or ID) into single objects with all their properties merged. Understanding the Problem We need to create a JavaScript function that takes an array of objects and groups them by a common property (like 'name'), merging all properties of objects that share the same value for that property. Input: [ {name: 'Adi', age: 22, color:'Black'}, {name: 'Adi', weight: 40, height: ...

Read More

Finding sum of all numbers within a range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 837 Views

Problem We are required to write a JavaScript function that takes in an array that specifies a range. Our function should find and return the sum of all the natural numbers falling in the range including the range numbers. Example Following is the code − const range = [4, 67]; const findSum = ([l, h]) => { let sum = 0; for(let i = l; i { // Formula: Sum = n * (first + last) / 2 // where ...

Read More

Return the nearest greater integer of the decimal number it is being called on in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 307 Views

The Math.ceil() function returns the smallest integer greater than or equal to a given number. This means it "rounds up" to the nearest integer. Syntax Math.ceil(x) Parameters x: A number to round up to the nearest integer. Return Value Returns the smallest integer greater than or equal to the given number. If the input is not a number, returns NaN. Example: Basic Usage console.log(Math.ceil(4.3)); // 5 console.log(Math.ceil(4.8)); // 5 console.log(Math.ceil(5.0)); // 5 (already integer) console.log(Math.ceil(-2.3)); // -2 console.log(Math.ceil(-2.8)); // -2 ...

Read More

Product of subarray just less than target in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument, and a number, target, as the second argument. Our function is supposed to count and return the number of (contiguous) subarrays where the product of all the elements in the subarray is less than target. Problem Example For example, if the input to the function is: const arr = [10, 5, 2, 6]; const target = 100; The expected output is: 8 The 8 subarrays that have product less ...

Read More

How to negate a predicate function in JavaScript?

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

In JavaScript, a predicate function is a function that returns a Boolean value. In other words, it is a function that tests whether a certain condition is true or false. There are times when we need to negate a predicate function. That is, we need to return the opposite Boolean value. There are several ways to negate a predicate function in JavaScript. Using the ! operator (Logical NOT) The most common way to negate a predicate function is to use the ! operator. For example, consider the following predicate function − function isEven(num) ...

Read More

How to add stroke to Text using FabricJS?

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

In this tutorial, we are going to learn how to add stroke to 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 add stroke by using the stroke property. Syntax new fabric.Text(text: String, { stroke: String }: Object) Parameters text ...

Read More

How to create a String representation of a Line object using FabricJS?

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

In this tutorial, we are going to learn about how to create a String representation of a Line object using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to create a String representation of a Line object, we use the toString method. ...

Read More

How does inline JavaScript work with HTML?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 7K+ Views

In this article, you will understand how inline JavaScript works with HTML. Inline JavaScript represents a code block written in between the tags in an HTML file. The advantage of using inline JavaScript in HTML files is to reduce the round trip of the web browser to the server. What is Inline JavaScript? Inline JavaScript is JavaScript code that is embedded directly within HTML documents using tags. This approach allows you to execute JavaScript without creating separate .js files, making it convenient for small scripts and quick implementations. Example 1: Basic Inline JavaScript Let ...

Read More
Showing 15471–15480 of 61,297 articles
Advertisements