Articles on Trending Technologies

Technical articles with clear explanations and examples

Determining sum of array as even or odd in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 473 Views

Problem We are required to write a JavaScript function that takes in an array of integers arr. Our function should return the string 'odd' if the sum of all the elements of the array is odd or 'even' if it's even. Example Following is the code − const arr = [5, 1, 8, 4, 6, 9]; const assignSum = (arr = []) => { const sum = arr.reduce((acc, val) => { return acc + val; }, 0); ...

Read More

Finding the sum of minimum value in each row of a 2-D array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 364 Views

Problem We are required to write a JavaScript function that takes in a 2-D array of numbers. Our function should pick the smallest number from each row of the 2-D array and then finally return the sum of those smallest numbers. Example Following is the code − const arr = [ [2, 5, 1, 6], [6, 8, 5, 8], [3, 6, 7, 5], [9, 11, 13, 12] ]; const sumSmallest = (arr = []) => { const findSmallest = array => ...

Read More

How to use JavaScript to play a video on Mouse Hover and pause on Mouseout?

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

In this article, we will explore how to use event listeners to control video playback with mouse interactions. We'll use the mouseover and mouseout events to automatically play and pause a video when the user hovers over it. The main functionality includes playing the video whenever the mouse hovers over the video element and pausing the video when the mouse leaves the video area. How It Works We attach event listeners to a video element in the DOM. When the browser detects a mouseover event, it triggers a JavaScript function to play the video. Similarly, when a ...

Read More

How to create a Rectangle with text cursor on hover over objects using FabricJS?

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

In this tutorial, we are going to create a Rectangle with a text cursor on hover over objects using FabricJS. text is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Rect({ hoverCursor: String }: Object) Parameters Options ...

Read More

How to set the angle of rotation of an instance in Text using FabricJS?

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

In this tutorial, we are going to learn how to set the angle of rotation of an instance in 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. Similarly, we can also set the angle of rotation of an instance by using the rotate method. Syntax rotate(angle: Number) ...

Read More

Hot Reload in ElectronJs

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

Hot reloading is a powerful feature in ElectronJS that lets developers quickly view their code changes in real time without having to restart the application. It makes the development process faster and more efficient by reducing the time and effort required to test changes. Steps to Implement Hot Reload in ElectronJS The hot reloading feature is implemented using a library called "electron-reload", and it can be easily integrated into an Electron JS application by following a few simple steps. Install the electron-reload module The first step in implementing hot reload in Electron JS is to install ...

Read More

I'm trying to make an id searcher which does a thing when you input the right id. However, the JavaScript if statement always runs. How?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 118 Views

In JavaScript, using the assignment operator (=) instead of comparison operators (== or ===) in an if statement causes the condition to always evaluate as true. This is because assignment returns the assigned value, which is typically truthy. The Problem: Assignment vs Comparison When you accidentally use = in a condition, you're assigning a value instead of comparing: let searchId = 10001; let currentId = 10002; // Wrong: This assigns searchId to currentId and always runs if (currentId = searchId) { console.log("This always runs! currentId is now:", currentId); } // ...

Read More

Implement Bubble sort with negative and positive numbers – JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 982 Views

Bubble sort is a simple sorting algorithm that works by repeatedly comparing adjacent elements and swapping them if they're in the wrong order. It works equally well with arrays containing both negative and positive numbers. Let's say the following is our unsorted array with negative and positive numbers: var arr = [10, -22, 54, 3, 4, 45, 6]; How Bubble Sort Works Bubble sort compares each pair of adjacent elements and swaps them if the first element is greater than the second. This process continues until no more swaps are needed, meaning the array ...

Read More

How to merge two object arrays of different size by key in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 876 Views

When working with object arrays of different sizes, we often need to merge them based on a common key. This is useful when combining data from different sources that share a common identifier. Suppose we have an object like this: const obj = { "part1": [{"id": 1, "a": 50}, {"id": 2, "a": 55}, {"id": 4, "a": 100}], "part2":[{"id": 1, "b": 40}, {"id": 3, "b": 45}, {"id": 4, "b": 110}] }; We need to merge part1 and part2 arrays to form a single array where objects with the same id ...

Read More

Finding square root of a number without using Math.sqrt() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 863 Views

We are required to write a JavaScript function that takes in a positive integer as the only argument. The function should find and return the square root of the number provided as the input. Newton's Method (Recommended) The most efficient approach is Newton's method (also called the Babylonian method), which uses iterative approximation to converge on the square root. const squareRoot = (num, precision = 0) => { if (num deviation) { res -= ((res ** 2) - num) / (2 * res); ...

Read More
Showing 16061–16070 of 61,297 articles
Advertisements