Aayush Mohan Sinha

Aayush Mohan Sinha

89 Articles Published

Articles by Aayush Mohan Sinha

Page 2 of 9

How to add bootstrap toggle-switch using JavaScript?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 1K+ Views

The Bootstrap library provides a number of features to the user to make their coding experience smooth. One of such features which the user can choose from is the toggle-switch. The toggle-switch, one of its useful features, provides users the ability to add components which can switch between two states such as on and off. Bootstrap Toggle-switch The Cascading Style Sheets (CSS) framework Bootstrap is a toolkit that makes it simpler and more standards-compliant to create websites. It can be used, alongside JavaScript, to create a responsive user interface. The simple Bootstrap toggle-switch component is used to select ...

Read More

How to Catch a ReferenceError with onerror?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 241 Views

JavaScript's onerror event provides a global way to catch errors, including ReferenceErrors, that occur during script execution. This is particularly useful for handling errors that might not be caught by traditional try-catch blocks. What is ReferenceError? A ReferenceError occurs when trying to access a variable or object that doesn't exist. This commonly happens with misspelled variable names or accessing variables before they're declared. Example of ReferenceError try { ...

Read More

How to Catch all JavaScript Errors and Send them to the Server?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 562 Views

JavaScript error handling is crucial for maintaining robust web applications. The window.onerror event allows you to catch all JavaScript errors globally and send them to your server for monitoring and debugging purposes. Understanding window.onerror The window.onerror event fires whenever an uncaught JavaScript error occurs in your application. It provides detailed information about the error including location and error details. Syntax window.onerror = (message, source, lineno, colno, error) => { // Handle error }; Parameters message: A string containing the error message that describes ...

Read More

How to Change a Button Text on Click Using LocalStorage in Javascript?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 594 Views

JavaScript provides powerful tools to create interactive web pages. In this article, we'll learn how to change a button's text when clicked and persist that change using localStorage, so the new text remains even after refreshing the page. What is localStorage? The localStorage is a read-only property of the window interface that allows you to store data permanently in the user's browser. Unlike sessionStorage, data stored in localStorage persists even when the browser session ends, making it perfect for remembering user preferences. localStorage Methods localStorage provides two essential methods for data manipulation: Getting Data ...

Read More

How to Change an HTML Element Name Using jQuery?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 1K+ Views

jQuery is a JavaScript library created to make event handling, CSS animation, Ajax, and DOM tree navigation and manipulation easier. In this article we are going to see how we can change the name of an element using jQuery. Algorithm We are going to follow a three−way procedure to change the name of any element using jQuery: Identify and select the element we want to change. Copy all the attributes of the selected element to a temporary object. Create a new element with the ...

Read More

Number pattern in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 5K+ Views

Number patterns in JavaScript are essential for developers who want to create visually appealing outputs and understand algorithmic thinking. These patterns involve generating sequences of numbers that follow specific rules or arrangements, helping developers grasp mathematical concepts that underlie complex algorithms. What are Number Patterns? Number patterns are sequences of numbers arranged in specific formations, typically displayed in triangular or pyramid structures. Each pattern follows a mathematical rule that determines how numbers are positioned and incremented. Pattern 1: Zero-Padded Triangle This pattern creates a triangular structure where each row contains numbers from 1 to the row ...

Read More

Representing seconds in HH:MM:SS in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 3K+ Views

Converting seconds to HH:MM:SS format is a common requirement in JavaScript applications for displaying durations, timers, and time intervals in a readable format. This article explores three practical methods to achieve this conversion. Problem Statement Given a number representing the duration in seconds, the task is to write a JavaScript function that converts the given duration into the format HH:MM:SS, where HH represents hours, MM represents minutes, and SS represents seconds. Sample Input: const durationInSeconds = 3665; Sample Output: 01:01:05 In this case, the input durationInSeconds is 3665, which represents a ...

Read More

Using Kadane’s algorithm to find maximum sum of subarray in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 732 Views

Kadane's algorithm is a powerful dynamic programming technique used to find the maximum sum of a contiguous subarray within an array. This algorithm is particularly useful for solving problems involving sequences of numbers where you need to find the optimal contiguous subsequence. Problem Statement Given an array of integers, find the contiguous subarray with the maximum sum and return that sum. Sample Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] Sample Output: Maximum sum: 6 (from subarray [4, -1, 2, 1]) Method 1: Naive Approach The ...

Read More

Removing all spaces from a string using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several efficient methods to remove all spaces from a string. This is a common requirement in web development for tasks like data validation, formatting user input, or preparing strings for processing. Problem Statement Given a string containing spaces, we need to remove all space characters to create a continuous string without any gaps. Sample Input: "Hello world! This is a test string." Sample Output: "Helloworld!Thisisateststring." Methods to Remove Spaces We'll explore four different approaches to solve this problem: Using Regular Expression with ...

Read More

Repeating string for specific number of times using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several methods to repeat a string for a specific number of times. This functionality is useful for generating patterns, creating padding, or building repeated text sequences in web applications. Problem Statement Write a JavaScript function that takes a string and a positive integer as input and returns a new string that repeats the input string for the specified number of times. If the input string is empty or the specified number of times is zero, the function should return an empty string. Sample Input: String: "Hello" Number of Times: 3 Sample Output: ...

Read More
Showing 11–20 of 89 articles
« Prev 1 2 3 4 5 9 Next »
Advertisements