Articles on Trending Technologies

Technical articles with clear explanations and examples

How to set the height of a Triangle using FabricJS?

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

In this tutorial, we are going to learn how to set the height of a Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. We can manipulate a triangle object by changing its position, opacity, stroke and also its dimension. FabricJS allows us to control an object's dimensions by using the width and height properties. Syntax new fabric.Triangle({ height: Number }: Object) Parameters ...

Read More

What is Variable Shadowing in JavaScript?

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

In programming, shadowing occurs when a variable declared in a certain scope (e.g. a local variable) has the same name as a variable in an outer scope (e.g. a global variable). When this happens, the outer variable is said to be shadowed by the inner variable. In JavaScript, variables can be shadowed in both the global and function scope. Global variables can be shadowed by function-scoped variables, and function-scoped variables can be shadowed by block-scoped variables declared with the let or const keyword. Variable Shadowing in the Global Scope In the global scope, shadowing occurs when a ...

Read More

How to truncate an array in JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 3K+ Views

This tutorial is going to be about truncating an array in JavaScript. Truncating an array means trimming some elements from the end and assigning back the new value of the truncated array to the actual array. Sometimes we need to truncate an array. For example, if there is an array with sorted elements in descending order, and we need only the first k sorted elements from the array. Instead of creating an extra array and modifying that, we can directly truncate the original array. There are several ways to truncate an array. Let's explore these methods. Syntax ...

Read More

How to add underline to Text using FabricJS?

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

In this tutorial, we are going to learn how to add underline 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 overline, line height which can be obtained by the properties textAlign, overline and lineHeight respectively. Similarly we can also add underline to text by using the underline property. Syntax new fabric.Text(text: String , { underline: Boolean }: Object) Parameters ...

Read More

How does Promise.any() method differs from Promise.race() method in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

In this article, you will understand how Promise.any() method differs from Promise.race() method in JavaScript. The Promise.any() method resolves when the first promise succeeds (fulfills), ignoring rejections until all promises fail. The Promise.race() method settles when the first promise completes, regardless of whether it succeeds or fails. Promise.any() Method Promise.any() waits for the first successful promise and ignores rejections. If all promises reject, it throws an AggregateError. console.log("Defining three promise values: promise1, promise2 and promise3"); const promise1 = Promise.resolve(1); const promise2 = new Promise((resolve, reject) => { setTimeout(resolve, 200, 'Promise Two'); }); ...

Read More

Number of vowels within an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 807 Views

We are required to write a JavaScript function that takes in an array of strings, (they may be a single character or greater than that). Our function should simply count all the vowels contained in the array. Example Let us write the code − const arr = ['Amy', 'Dolly', 'Jason', 'Madison', 'Patricia']; const countVowels = (arr = []) => { const legend = 'aeiou'; const isVowel = c => legend.includes(c.toLowerCase()); let count = 0; arr.forEach(el => { for(let ...

Read More

Merging subarrays in JavaScript

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

This problem demonstrates how to merge subarrays containing email data by grouping emails under the same person's name. We'll use JavaScript's Set data structure to eliminate duplicates and organize the data efficiently. Understanding the Problem Given an array of subarrays where each subarray contains a person's name followed by their email addresses, we need to merge all emails belonging to the same person into a single subarray. For example, if "Ayaan" appears in multiple subarrays with different emails, we should combine all of Ayaan's emails into one subarray. Algorithm Step 1 − Create a function that ...

Read More

Returning a range or a number that specifies the square root of a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 227 Views

We need to write a JavaScript function that takes an integer n and returns either the exact square root (if n is a perfect square) or a range indicating where the square root falls between two consecutive integers. Problem Requirements Return integer k if n is a perfect square, such that k * k == n Return a range (k, k+1) if n is not a perfect square, where k * k < n and n < (k+1) * (k+1) Solution Approach We use Math.sqrt() to calculate the ...

Read More

Are bits alternating in integer using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 244 Views

We are required to write a JavaScript function that takes in an integer, num, as the first and the only argument. Our function should check whether the binary representation of num has alternating bits − namely, if two adjacent bits will always have different values. For example, if the input to the function is 5, the output should be true because the binary form of 5 is 101 which has alternating bits (1-0-1). Understanding Alternating Bits Alternating bits mean that no two adjacent bits in the binary representation are the same. For instance: 5 ...

Read More

How to create a canvas with crosshair cursor on hover over objects using FabricJS?

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

In this article, we are going to create a canvas with a crosshair cursor on hover using FabricJS. The crosshair is one of the native cursor styles available which can be used in FabricJS canvas. FabricJS provides various cursor types like default, all-scroll, crosshair, col-resize, row-resize etc., which reuse native CSS cursors. The hoverCursor property sets the cursor style when hovering over canvas objects. Syntax new fabric.Canvas(element: HTMLElement|String, { hoverCursor: String }: Object) Parameters element − This parameter is the element itself ...

Read More
Showing 15511–15520 of 61,297 articles
Advertisements