In JavaScript, you can use variables as object keys using bracket notation or computed property names. This is useful when working with dynamic data, API responses, or when key names are determined at runtime. Using Bracket Notation (After Object Creation) The most common approach is to create the object first, then add properties using bracket notation: Using variables as key of JavaScript object let content = document.getElementById("content"); ... Read More
Testing JavaScript code automatically helps ensure our code works as intended and catches bugs early in development. This article covers the main types of automated testing and popular frameworks for JavaScript applications. Types of JavaScript Testing Unit Testing Unit testing verifies individual functions, modules, or components in isolation. The goal is to test the smallest pieces of code to ensure they work correctly. Popular JavaScript unit testing frameworks include Jest and Mocha. Integration Testing Integration testing verifies how different parts of your JavaScript code work together. It ensures that various components interact properly when combined. Frameworks like ... Read More
JavaScript is an object-oriented, interpreted scripting language that serves as the backbone of modern web development. It's primarily a client-side scripting language used to create dynamic and interactive websites. While HTML structures web content and CSS handles styling, JavaScript adds functionality like interactivity, animations, and real-time user experiences. Beyond web browsers, JavaScript has expanded into mobile application development, server-side implementation, and game development. Developers frequently use JavaScript with popular front-end frameworks like React.js, Angular.js, and Vue.js to build complex, dynamic web applications. In full-stack development, JavaScript powers both front-end interfaces and back-end services through Node.js. Why We Need ... Read More
In this tutorial, we will discuss two approaches to finding the intersection point of two linked lists in JavaScript. The first approach uses nested loops, and the second approach uses the difference of nodes technique which works in linear time. We will be given two linked lists that may intersect at some point. The intersection point is where both lists share the same node reference (not just the same value). After the intersection point, all subsequent nodes are identical in both lists. Problem Statement Given two linked lists, we need to find the node where they intersect. ... Read More
In this tutorial, we will learn the fastest way to convert JavaScript NodeList to Array. NodeList is a similar structure to an array; it is a collection of DOM (Document Object Model) elements. However, array methods like 'map()', 'filter()', and 'slice()' cannot be used on NodeList objects. There are several ways to convert NodeList to Array, but this task can be done faster using these approaches: Using Array.from() function (Recommended) Using spread operator (...) By iterating with for loop Using Array.from() (Recommended) The Array.from() method ... Read More
In this program, we are given an array of integers with even length. We need to form groups of size two using array elements, then find the maximum difference between the group with the highest sum and the group with the lowest sum. Problem Statement Given an array of even length, we must partition it into groups of size two. Our goal is to find the maximum possible difference between the sum of any two groups. This means finding the highest sum group and the lowest sum group, then returning their difference. Examples Example 1: ... Read More
Are you also willing to add a custom audio recording feature to your web application? If yes, you are in the right place, as we will learn to record and play audio using JavaScript in this tutorial. Some applications like Discord allow you to record the audio and store it inside that to play it anytime. The recorded audio can also be used as a meme for fun, alerts in the discord meetings, etc. We can also use the MediaRecorder API of JavaScript to add the recording audio feature to our web application. Here, we will learn a ... Read More
To change the background color after clicking the button in JavaScript, we are going to discuss two different approaches. We have to perform two simple tasks: adding a click event listener and changing the background color of the document. In this article our task is to understand how to change the background color after clicking the button in JavaScript. Approaches to Change Background Color on Clicking Button Here is a list of approaches to change the background color after clicking the button in JavaScript which we will be discussing in this article with stepwise explanation and complete ... Read More
The equilibrium sum of an array is found at an index where the sum of elements from the start to that index (inclusive) equals the sum of elements after that index. When multiple equilibrium points exist, we need to find the maximum sum among them. Problem Statement Given an array, find the maximum equilibrium sum where: Left sum includes elements from index 0 to current index (inclusive) Right sum includes elements after the current index (exclusive) Left sum equals right sum at the equilibrium point Example ... Read More
AP is the arithmetic progression in which the difference between two consecutive elements is always the same. We will print all the triplets in a sorted array that form AP using three approaches: Naive approach, binary search method and two-pointer approach. Introduction to Problem In this problem we are given a sorted array meaning all the elements are in increasing order. We have to find three elements which are part of the array and form an AP. For example − Given array: [1, 5, 2, 4, 3] From the given array we have triplets like [2, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance