Articles on Trending Technologies

Technical articles with clear explanations and examples

The PriorityQueue Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 279 Views

A Priority Queue is a data structure where each element has an associated priority. Elements with higher priority are served before elements with lower priority. In JavaScript, we can implement this using a class-based approach. Complete PriorityQueue Implementation Here's a complete implementation of the PriorityQueue class with all essential methods: class PriorityQueue { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; ...

Read More

How to get a part of string after a specified character in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 16K+ Views

To get a part of a string after a specified character in JavaScript, you can use the substring() method combined with indexOf(). This technique allows you to extract portions of text before or after any character. Understanding substring() The substring() method extracts characters from a string between two specified indices. It takes a start index (inclusive) and an optional end index (exclusive). Syntax for Getting Text After a Character string.substring(string.indexOf(character) + 1); Here, indexOf(character) finds the position of the character, and adding + 1 starts extraction from the next position. Syntax for ...

Read More

How to make a list of partial sums using forEach JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 356 Views

In JavaScript, creating a list of partial sums (also known as cumulative sums) means generating a new array where each element represents the sum of all elements up to that position in the original array. We have an array of numbers like this: const arr = [1, 1, 5, 2, -4, 6, 10]; We need to create a function that returns a new array where each element is the sum of all previous elements including itself: const output = [1, 2, 7, 9, 5, 11, 21]; Using forEach Method The ...

Read More

JavaScript program to merge two objects into a single object and adds the values for same keys

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 587 Views

We have to write a function that takes in two objects, merges them into a single object, and adds the values for same keys. This has to be done in linear time and constant space, means using at most only one loop and merging the properties in the pre-existing objects and not creating any new variable. So, let's write the code for this function − Example const obj1 = { value1: 45, value2: 33, value3: 41, value4: 4, ...

Read More

How to check if a variable is an integer in JavaScript?

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

In this tutorial, we will learn to check if a variable is an integer in JavaScript. Before we solve the problem, we must have a problem. We can ask ourselves, "why do we need to check if the variable is an integer?". Let's understand the answer using a single example. Suppose, we are taking the value from the user using the input text box. It returns the values in the string format, and now think that we are adding values. Will we get the correct result? Obviously, not. So, in such cases, we need to check if the variable is ...

Read More

Set how the item will shrink relative to the rest with JavaScript?

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

In this tutorial, let us look at the way to set how much the item will shrink relative to the rest of the elements in JavaScript. To set item shrink relative to the rest of the elements, we can utilize JavaScript's flexShrink property. Let's take a quick look at this. Using the Style flexShrink Property The flexShrink property specifies how much a flex item will shrink according to the other items in the same container. The element must be flexible for the flexShrink property to function. The property's value functions as a ratio. For instance, if ...

Read More

How to handle mousedown and mouseup with HTML5 Canvas

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 923 Views

To handle the mousedown and mouseup events with HTML5 Canvas, you can attach event listeners directly to the canvas element. These events are useful for creating interactive graphics, drag-and-drop functionality, or drawing applications. Basic Syntax canvas.addEventListener('mousedown', function(event) { // Handle mouse press }); canvas.addEventListener('mouseup', function(event) { // Handle mouse release }); Example: Simple Click Detection const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); let mouseDown = false; // Draw initial state ctx.fillStyle = '#f0f0f0'; ctx.fillRect(0, 0, 400, 300); ctx.fillStyle = ...

Read More

What is the main difference between objects created using object literal and constructor function?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

The main difference between objects created using object literal and constructor function lies in how they handle references and instances. Objects created with object literals are referenced by variables, while constructor functions create independent instances. Let's explore both approaches with examples to understand this fundamental difference. Objects Created Using Object Literal When you create an object using object literal syntax and assign it to multiple variables, all variables point to the same object in memory. This means any change made through one variable affects all other variables referencing that object. Example ...

Read More

Window innerWidth and innerHeight Properties in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 257 Views

The window.innerWidth and window.innerHeight properties return the width and height of the browser window's content area, excluding toolbars, scrollbars, and borders. Syntax let width = window.innerWidth; let height = window.innerHeight; Properties innerWidth - Returns the interior width of the window in pixels innerHeight - Returns the interior height of the window in pixels Both properties are read-only and return integer values Values change when the browser window is resized Example Window Dimensions ...

Read More

Shared properties in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 449 Views

In JavaScript, properties can be shared across all instances of an object by attaching them to the constructor function's prototype property. This creates a single shared property that all instances can access, rather than each instance having its own copy. How Prototype Properties Work When you access a property on an object, JavaScript first checks if the property exists on the instance itself. If not found, it looks up the prototype chain to find the property on the constructor's prototype. Student.prototype school: "St Marks" ...

Read More
Showing 17651–17660 of 61,297 articles
Advertisements