Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 5 of 80

How to conditionally add a member to an object using JavaScript?

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

Objects are fundamental data structures in JavaScript, and developers often need to add properties conditionally based on certain criteria. For example, adding a "drivingLicense" property to a person object only if they are 18 or older. Here, we will explore different approaches to conditionally add members to JavaScript objects. Using the Spread Operator The spread operator provides an elegant way to conditionally add properties during object creation or update. Syntax let obj = { ...(condition ? { prop: 'value' } : {}) } If the condition is true, it ...

Read More

JavaScript Program to Count Inversions of size three in a given array

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

In this tutorial, we will learn to count inversions of size three in a given array. An inversion of size three is a triplet of indices (i, j, k) where i < j < k but arr[i] > arr[j] > arr[k]. Problem Statement: Given an array of length n containing different numeric entries, we need to find the total number of triplets (i, j, k) such that arr[i] > arr[j] > arr[k], where i < j < k. We'll explore two approaches: a brute force method and an optimized solution using nested loops. Using the Brute Force ...

Read More

JavaScript Program to Count Rotations Divisible by 4

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

In this tutorial, we will learn to count the total number of rotations divisible by 4 for the given number. Problem statement − We have given a number value. We need to rotate numbers in clockwise or anti-clockwise directions and count the total number of rotations divisible by 4. Here, we will learn two different approaches to counting rotations divisible by 4. Understanding Number Rotation When we rotate a number, we move digits from one position to another. For example, rotating 1234 clockwise gives us: 4123, 3412, 2341, and back to 1234. Each rotation creates a ...

Read More

JavaScript Program to Count Rotations Divisible by 8

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

In this tutorial, we'll learn how to count the number of rotations of a given number that are divisible by 8. A rotation means moving digits from one end to another - for example, rotating 123 gives us 231, 312, and back to 123. We'll explore two different approaches: the straightforward rotation method and an optimized approach using divisibility rules. Understanding Number Rotation When we rotate a number, we take the last digit and move it to the front. For example, rotating 1234 gives us these possibilities: 1234 (original) 4123 (moved 4 to front) 3412 (moved ...

Read More

How to Configure Mouse Wheel Speed Across Browsers using JavaScript?

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

We can use JavaScript to control the mouse wheel scrolling behavior across different browsers. Every browser has a default scrolling speed, but we can customize it to create better user experiences, such as smooth scrolling animations or controlled reading speeds. Different browsers support different wheel events, so we need to handle multiple event types to ensure cross-browser compatibility. This tutorial demonstrates various approaches to configure mouse wheel speed using JavaScript. Syntax The basic syntax for controlling mouse wheel speed uses the 'wheel' event: element.addEventListener("wheel", (event) => { event.preventDefault(); ...

Read More

How to control fps with requestAnimationFrame?

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

The fps (frames per second) is crucial for animations and games, determining how many times the screen updates per second. JavaScript's requestAnimationFrame() typically runs at 60fps, but we can control this rate using different approaches. For example, a video is a continuous sequence of images shown at short intervals. Higher fps provides smoother animations, while lower fps can create choppy effects. Understanding fps control helps optimize performance and create desired visual effects. Using setTimeout() with requestAnimationFrame The setTimeout() function can delay requestAnimationFrame() calls to control fps. We calculate the interval as 1000/fps milliseconds. Syntax ...

Read More

How to create a reporting app with Vue 3 and Composition API?

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

Vue 3 with Composition API provides a powerful way to build reporting applications. This tutorial demonstrates creating a data-driven report table that fetches information from an external API and displays it in a structured format. What is a Reporting App? A reporting app displays data in organized formats like tables, charts, or dashboards. It transforms raw data into meaningful insights for users to analyze business metrics, user statistics, or any structured information. Composition API Benefits The Composition API allows logic-based component organization instead of lifecycle-based structure. This approach creates more maintainable, reusable, and testable code by ...

Read More

What is the App Shell Model in JavaScript?

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

The App Shell Model is a design pattern that separates a web app's UI shell from dynamic content. The shell includes the core HTML, CSS, and JavaScript needed for the interface, while content is loaded dynamically. This approach is fundamental to Progressive Web Apps (PWAs) for improved performance and user experience. What is the App Shell? The app shell consists of the minimal HTML, CSS, and JavaScript required to power the user interface. It includes: Navigation and header components Layout structure and styling Loading indicators and placeholders ...

Read More

How to concatenate regex literals in JavaScript?

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

Regular expressions (regex literals) are patterns used to match character combinations in strings. Sometimes, you need to combine multiple regex patterns into a single expression. Unlike strings, regex literals cannot be concatenated directly with the '+' operator. To concatenate regex literals, you must extract their source patterns and flags, combine them properly, and create a new RegExp object. Syntax Follow this approach to concatenate regex literals: let allFlags = regex1.flags + regex2.flags; let uniqueFlags = [...new Set(allFlags.split(''))].join(''); let combined = new RegExp(regex1.source + regex2.source, uniqueFlags); This extracts the source patterns and flags from ...

Read More

Find the OR and AND of Array elements using JavaScript

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

In JavaScript, we can use the '&&' operator to perform the AND operation between two elements and the '||' operator to perform OR operation between two elements. Here, we will learn to perform OR and AND operations between every element of the array using different approaches. Use the for Loop We can use the for loop to iterate through the array elements and perform OR or AND operations with all array elements. Syntax Users can follow the syntax below to use the for loop to take OR or AND operation of every element. ...

Read More
Showing 41–50 of 793 articles
« Prev 1 3 4 5 6 7 80 Next »
Advertisements