Saurabh Jaiswal

Saurabh Jaiswal

33 Articles Published

Articles by Saurabh Jaiswal

Page 2 of 4

How to convert NaN to 0 using JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 4K+ Views

We can use the logical OR operator, double bitwise NOT operator, strict equality operator, or the isNaN() function to convert NaN to 0 using JavaScript. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. In this article, we will learn different approaches to convert NaN to 0. Using the Logical OR (||) Operator Using the Double Tilde (~~) Operator Using the Strict Equality (===) Operator Using the isNaN() function Using the Logical OR (||) Operator ...

Read More

How to call JavaScript function in an alert box?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 6K+ Views

To call a JavaScript function in an alert box, you can use the alert() function, a built-in function in JavaScript that displays an alert dialog with a specified message. An alert box is a simple dialog box that displays a message to the user and provides an OK button. It is a built-in function in JavaScript that is often used for debugging or displaying simple notifications to the user. Here's an example of how to use the alert() function in JavaScript: alert("Hello, World!"); ...

Read More

How to add many Event Handlers to the same element with JavaScript HTML DOM?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 13K+ Views

When building interactive web applications, you often need to handle multiple events on the same element. For example, a button might respond to both clicks and hover events. JavaScript provides several approaches to attach multiple event listeners to a single DOM element efficiently. Using Multiple addEventListener Methods Using Array.forEach() for Event Registration Using Multiple addEventListener Methods The addEventListener method is the standard way to attach event handlers in JavaScript. You can call it multiple times on the same element to register different event types, each with their ...

Read More

How to catch all JavaScript errors?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 13K+ Views

To catch all JavaScript errors, we can use the window.onerror method which acts like a global try-catch statement. The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page. The onerror event handler provides three pieces of information to identify the exact nature of the error: Error message − The same message that the browser would display for the given error URL − The file in which the error occurred ...

Read More

How to add an element in the last of a JavaScript array?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 6K+ Views

In this tutorial, we will learn how to add an element to the last of a JavaScript array. The most common method to add an element to the end of the array is by using the Array push() method, but we will discuss multiple methods to achieve this. Using the Array.prototype.push() Method Using the Array.prototype.splice() Method Using Array Indexing Using the Array.prototype.push() Method To add an element at the end, use the JavaScript push() method. The push() method appends the given element(s) to the end of the array and ...

Read More

How to Add New Value to an Existing Array in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 4K+ Views

To add new value to an existing array in Javascript, it can be achieved using various ways. We will be understanding seven different approaches for adding a new element to existing array. In this article we are having an array of numbers and our task is to add new value to an existing array in JavaScript. Approaches to Add New Value to Existing Array Here is a list of approaches to add new value to an existing array in JavaScript which we will be discussing in this article with stepwise explanation and complete example codes. ...

Read More

How null is converted to Number in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 10K+ Views

In JavaScript, null is a primitive value that represents the intentional absence of any object value. When null is converted to a number, it becomes 0. This article explores various methods to convert null to a number in JavaScript. Using Number() Method Using Logical OR (||) Using the ~~ operator Using Ternary Operator Using arithmetic operations Using the Number() Method The Number() method is the most straightforward way to convert null to a number. It explicitly converts null to 0. Syntax Number(null) Example ...

Read More

How to attach one or more drop-shadows to the box with JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 2K+ Views

To attach one or more drop shadows to a box with JavaScript, you can use the boxShadow style property. You can specify the shadow's horizontal offset, vertical offset, blur radius, spread radius, and color. Syntax Following is the syntax to add one or more drop shadows to the box with JavaScript: element.style.boxShadow = "offset-x offset-y blur-radius spread-radius color"; Parameters The boxShadow property accepts the following parameters: offset-x − Horizontal offset of the shadow. Positive values create a shadow on the right side, negative values on the left ...

Read More

How to call a JavaScript function on a click event?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 25K+ Views

To call a function on click event in JavaScript, you can use either the addEventListener method or the onclick event attribute. The addEventListener method is a general way to attach an event handler to a DOM element, and it allows you to specify the event and the callback function to be called when the event occurs. The onclick attribute is a specific event attribute that allows you to specify a JavaScript function to be called when the element is clicked. Both methods allow you to specify a function to be called when the element is clicked, but the addEventListener ...

Read More

How to add 30 minutes to a JavaScript Date object?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 12K+ Views

In JavaScript, there are multiple ways to add 30 minutes to a Date object. This tutorial covers two effective methods: using the setMinutes() method and using the getTime() method. Using the setMinutes() Method The setMinutes() method sets the minutes for a date object and automatically handles overflow to the next hour or day. Syntax Date.setMinutes(min, sec, ms); Parameters min − An integer between 0 and 59, representing the minutes. sec − An integer between 0 and 59, representing the seconds. Optional. ms ...

Read More
Showing 11–20 of 33 articles
Advertisements