Javascript Articles

Page 15 of 534

JavaScript Program for Markov Matrix

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 274 Views

A matrix is a kind of 2-D array, which is in the form of some number of rows, and for each row, there is the same number of columns and by the row and column number, we can get the element at any particular index. For the Markov matrix, each row's sum must equal 1. We are going to implement a code to create a new Markov matrix and find if the currently given matrix is a Markov matrix or not. What is a Markov Matrix? A Markov matrix is a special type of matrix where each row ...

Read More

JavaScript Program for Maximize Elements Using Another Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 292 Views

In this article, we are going to implement a JavaScript program for maximizing elements using another array. We are given two arrays and have to pick some elements from the second array and replace the elements of the first array to maximize the sum. Problem Statement In this problem, we are given two arrays and we have to make all the elements of the first array as large as possible by replacing them with elements from the second array. Each element from the second array can only be used once. The goal is to maximize the sum of ...

Read More

JavaScript Program for Maximum Product Subarray

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 440 Views

A subarray is a contiguous portion of an array. In the maximum product subarray problem, we need to find the subarray whose elements have the largest product when multiplied together. This is a classic dynamic programming problem with interesting edge cases involving negative numbers and zeros. Problem Analysis The challenge becomes complex when dealing with different types of numbers: All positive numbers: The entire array gives maximum product Contains zeros: Array splits into segments at zero positions Contains negative numbers: Even count of negatives gives positive product, ...

Read More

6 JavaScript Optimization Tips from Google

Biswaindu Parida
Biswaindu Parida
Updated on 15-Mar-2026 333 Views

Google's performance optimization guidelines provide essential techniques for building fast, efficient JavaScript applications. These six key strategies can dramatically improve web application performance and user experience. Why JavaScript Optimization Matters JavaScript optimization is critical for modern web development because: Performance Impact − Optimized JavaScript reduces loading times and improves responsiveness, directly affecting user satisfaction and engagement. SEO Benefits − Search engines prioritize fast-loading sites, making optimization crucial for visibility and rankings. Resource Efficiency − Well-optimized code uses less CPU and memory, reducing server costs and improving scalability. User ...

Read More

How to show some custom menu on text selection?

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

In text editors like Microsoft Word, selecting text reveals a custom menu with formatting options like bold, italic, color changes, and alignment controls. This tutorial demonstrates how to create a similar custom context menu that appears when users select text on a webpage. How It Works The technique involves capturing mouse coordinates during selection and positioning a custom menu at the selection point. We use the getSelection() API to detect when text is selected and getBoundingClientRect() to calculate the menu position. Implementation Steps Step 1 − Create HTML structure with content div and hidden custom ...

Read More

How to store data to DOM?

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

Storing data in the DOM means keeping data associated with HTML elements or in JavaScript variables that can be accessed later. This is useful for maintaining application state, form data, or temporary values without making server requests. In vanilla JavaScript, we can store data in objects or use element properties. jQuery provides the data() method for attaching data to specific DOM elements. Let's explore both approaches. Using JavaScript Objects to Store Data The most common approach is creating JavaScript objects to hold data. This keeps information organized and easily accessible. Syntax let dataObj = ...

Read More

How to store JavaScript functions in a queue and execute in that order?

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

In JavaScript, you may need to store functions in a queue and execute them in a specific order. Since JavaScript doesn't have a built-in queue data structure, we can use arrays with push() to enqueue functions and shift() to dequeue them. This pattern is useful for managing asynchronous operations, implementing task schedulers, or controlling execution flow in applications. Basic Queue Operations A function queue uses these core operations: Enqueue: Add function to the end using push() Dequeue: Remove and execute function from the front using shift() Execute: Call functions in First-In-First-Out (FIFO) order ...

Read More

How to switch the language of the page using JavaScript?

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

Whenever you develop a website or application for a worldwide business, you must also focus on which language your audience can understand. For example, English is an international language, but in some parts of the world, people don't understand English as they speak German, Spanish etc. However, if you have observed, then some websites provide the option to change the website's language. You just need to click on the button, which changes the whole website's language. Have you ever thought about how it is possible? Here, we will learn to switch the language of the web page using ...

Read More

How to throw an error in an async generator function in JavaScript ?

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

Async generator functions combine asynchronous operations with generator functionality. When errors occur in async generators, they need special handling using throw() method or try-catch blocks with for await...of loops. What are Async Generator Functions? Async generators use async function* syntax and can yield values asynchronously. They return an async iterator that can be consumed with for await...of loops. Basic Async Generator Example let content = document.getElementById('content'); ...

Read More

How to throw an error when using a property of an object?

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

In JavaScript, objects contain properties in key-value format. When accessing non-existent properties, JavaScript returns undefined instead of throwing an error. However, you can implement custom error handling to throw errors when invalid properties are accessed. Default Behavior: Accessing Non-existent Properties By default, JavaScript returns undefined for non-existent properties: Default behavior when accessing object properties let content = document.getElementById('content'); let object = { ...

Read More
Showing 141–150 of 5,340 articles
« Prev 1 13 14 15 16 17 534 Next »
Advertisements