Articles on Trending Technologies

Technical articles with clear explanations and examples

Explain Asynchronous vs Deferred JavaScript

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 493 Views

When loading JavaScript files, the browser normally pauses HTML parsing to download and execute scripts. This can slow down page loading, especially with large JavaScript files. The async and defer attributes solve this problem by changing how scripts are loaded and executed. Normal Script Loading By default, scripts block HTML parsing until they finish downloading and executing: The browser stops parsing HTML, downloads the script, executes it, then continues parsing. This can create delays, especially with large scripts. Async Attribute The async attribute downloads scripts in parallel with HTML parsing. Once ...

Read More

Explain Promise.race() with async-await in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 1K+ Views

Promise.race() executes multiple promises concurrently and returns the result of whichever promise settles first, whether resolved or rejected. Unlike Promise.all(), it doesn't wait for all promises to complete. Syntax Promise.race(iterable) .then(result => { // Handle first settled promise }) .catch(error => { // Handle if first promise rejected }); // With async/await async function example() { try { const result = await Promise.race([promise1, promise2, promise3]); // Use result from first ...

Read More

Explain the working of timers in JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 802 Views

In JavaScript, timers are a very noteworthy feature. As like the normal watch timer, we can start the timer at a time and execute the function or code in JavaScript after a particular time. In simple terms, we can use the timer to execute the code after some delay. For example, when you visit some website, it shows the signup box after 3 to 4 minutes of your visit, and that we can achieve using JavaScript. We can set the delay timer to show the signup popup box. Another good example of the timer in real life is ...

Read More

Retaining array elements greater than cumulative sum using reduce() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 255 Views

We need to write a JavaScript function that takes an array of numbers and returns a new array containing only elements that are greater than the cumulative sum of all previous elements. We'll solve this using the Array.prototype.reduce() method. Problem Understanding For each element in the array, we compare it with the sum of all elements that came before it. If the current element is greater than this cumulative sum, we include it in the result array. Example Let's implement the solution using reduce(): const arr = [1, 2, 30, 4, 5, 6]; ...

Read More

How can I merge properties of two JavaScript objects dynamically?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 371 Views

To merge properties of two JavaScript objects dynamically, you can use the spread operator ({...object1, ...object2}) or Object.assign(). Both methods create a new object containing properties from multiple source objects. Using Spread Operator (Recommended) The spread operator is the modern and most concise approach: var firstObject = { firstName: 'John', lastName: 'Smith' }; var secondObject = { countryName: 'US' }; var mergedObject = {...firstObject, ...secondObject}; console.log(mergedObject); { firstName: 'John', lastName: 'Smith', countryName: 'US' } Using Object.assign() ...

Read More

Subtracting array in JavaScript Delete all those elements from the first array that are also included in the second array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 293 Views

Subtracting arrays in JavaScript involves removing all elements from the first array that exist in the second array. This operation is useful for filtering data and finding differences between datasets. Problem Statement Given two arrays, we need to delete all elements from the first array that are also present in the second array. const arr1 = ['uno', 'dos', 'tres', 'cuatro']; const arr2 = ['dos', 'cuatro']; // Expected output: ['uno', 'tres'] Using filter() with indexOf() The filter() method creates a new array with elements that pass a test. We use indexOf() to check ...

Read More

Fetch Numbers with Even Number of Digits JavaScript

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

In JavaScript, finding numbers with an even count of digits means identifying numbers where the total digit count is divisible by 2. This is different from finding even numbers themselves. Understanding the Problem We need to create a function that takes an array of numbers and returns only those numbers that have an even number of digits. For example, in the array [12, 345, 67, 8910, 11, 9], the numbers 12 (2 digits), 67 (2 digits), and 8910 (4 digits) have even digit counts. Method 1: Using String Length Convert each number to a string and ...

Read More

Pick out numbers from a string in JavaScript

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

In JavaScript, extracting numbers from strings is a common task that can be efficiently accomplished using regular expressions and built-in string methods. This approach allows you to find and extract numeric values from mixed content. Understanding the Problem The goal is to extract all numeric values from a given string. For example, from the string "I am 25 years old and earn $1500.50", we want to extract [25, 1500.50]. This involves pattern matching to identify numeric sequences including integers and decimal numbers. Using Regular Expressions with match() ...

Read More

Smallest number of perfect squares that sums up to n in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 398 Views

We need to write a JavaScript function that finds the minimum number of perfect squares that sum up to a given positive number. The function should find a combination of perfect square numbers (1, 4, 9, 16, 25, ...) which when added gives the input number, using as few perfect squares as possible. Problem Example If the input number is 123: Input: 123 Output: 3 Because 123 = 121 + 1 + 1 (using three perfect squares: 11², 1², 1²) Understanding the Pattern This is a classic Dynamic Programming problem. We ...

Read More

2 Key keyboard problem in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 310 Views

In this problem, we start with a notepad containing one character 'A' and need to reach exactly 'n' characters using only two operations: Copy All and Paste. The goal is to find the minimum number of steps required. Problem Understanding Given a notepad with one 'A', we can perform: Copy All − Copy all characters currently on the notepad Paste − Paste the previously copied characters We need to find the minimum steps to get exactly 'n' A's on the notepad. Example Walkthrough For ...

Read More
Showing 15101–15110 of 61,299 articles
Advertisements