Rushi Javiya

Rushi Javiya

137 Articles Published

Articles by Rushi Javiya

Page 2 of 14

How to check if a number evaluates to Infinity using JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 729 Views

In JavaScript, when we divide any number by zero, we get the infinity value. Also, developers can make a mistake in writing mathematical expressions which evaluate to Infinity. Before performing any operation with the returned value from mathematical expressions, we need to check if the number value is finite. Here, we will learn three approaches to check if a number evaluates to Infinity using JavaScript. Comparing with Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY In JavaScript, the Number object contains POSITIVE_INFINITY and NEGATIVE_INFINITY properties that represent positive and negative infinity values. We can compare our numerical value with these properties to ...

Read More

How to check if a string is html or not using JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 8K+ Views

When working with dynamic HTML content in JavaScript, it's crucial to validate HTML strings before inserting them into the DOM. Invalid HTML can break your webpage structure or cause rendering issues. This article explores two reliable methods to check if a string contains valid HTML using JavaScript. Using Regular Expression to Validate HTML Regular expressions provide a powerful way to match HTML patterns. We can create a regex pattern that identifies valid HTML tags with proper opening and closing structure. Syntax let regexForHTML = /]*>(.*?)/; let isValid = regexForHTML.test(string); Regex Pattern Explanation ...

Read More

How to check if the date is less than 1 hour ago using JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will learn to find the difference between two dates and check if the difference is less than one hour. Sometimes, developers must play with the Date object and perform some operation every hour. So, this can be one approach that checks if a particular operation is performed before an hour, perform it again; otherwise, wait to complete the hour. Here, we will learn different approaches to check if the date is less than 1 hour ago using JavaScript. Use the getTime() method The getTime() method returns the total milliseconds for the date from ...

Read More

How to check if one date is between two dates in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 2K+ Views

In JavaScript, we can use the Date() object to create different timestamps. Also, we may be required to check if one date is between two using JavaScript. For example, we want to create a filter for orders in the eCommerce application based on the dates. So, we should be able to filter all orders between the two dates that users enter into the date input field. Another real-world use case of checking one date between two is in the banking application. For example, while developing the banking system application, developers need to create a filter allowing users to ...

Read More

How to check if the string contains only digits in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 7K+ Views

We may require to find the string, which contains only digits but not any other characters while developing. The easiest way to check can parse the numbers from the string and compare its length with the original string's length. If both are the same, that means the string contains only digits. Users can use the parseInt() method to parse the numbers from the string. However, in this tutorial, we will learn other methods to check if the string contains only digits in JavaScript. Using the for-loop and charCodeAt() Method We can iterate through the string using the ...

Read More

How to check if the clicked element is a div or not in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 10K+ Views

When building interactive web applications, you often need to detect clicks on specific elements like divs. This is particularly useful for modals, dropdowns, or any clickable containers. This tutorial explores three effective methods to check if a clicked element is a div. Using the onClick Attribute The onClick attribute is the simplest way to detect clicks on a specific div element. You assign a function that executes when the div is clicked. Syntax This is a div! function clickFunction() { // perform operation on click ...

Read More

How to check input file is empty or not using JavaScript/jQuery?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 9K+ Views

In JavaScript, while working with the form elements, we need to validate the input fields and form elements when a user enters the value. In this tutorial, we will work with the file input. We will also learn to validate the file input. Sometimes, we may be required to check if the file is selected in the input field, then only enable the submit button; otherwise, disable the submit button. So, it will not allow users to submit the form or file without selecting it. Validate the file input using JavaScript In JavaScript, we can access the ...

Read More

Get the relative timestamp difference between dates in JavaScript

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 6K+ Views

Have you ever seen notifications on any website showing the time stamp? It shows something like "12 minutes ago", "2 days ago", "10 hours ago", etc. It is related to the timestamp difference between two dates or times. Also, some apps show that this device's last login was 22 hours ago. So, there are many uses to get the timestamp difference between two dates. In this tutorial, we will learn different approaches to get the relative timestamp difference between two dates. Using getTime() Method with Custom Algorithm In JavaScript, we can create a date object using ...

Read More

How to splice an array without mutating the original Array?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 4K+ Views

In JavaScript, the splice() method modifies the original array by adding, removing, or replacing elements. However, sometimes you need to perform splice operations without changing the original array. This tutorial demonstrates three effective approaches to splice arrays while preserving the original data. Understanding the splice() Method The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. Syntax array.splice(startIndex, deleteCount, item1, item2, ..., itemN) Parameters startIndex − The index at which to start changing the array deleteCount − The number of ...

Read More

How to Trigger a File Download when Clicking an HTML Button or JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 49K+ Views

To trigger a file download when clicking an HTML button or JavaScript, is a very common and important part of web page where users can directly download the file they want by clicking a button or link. We will be understanding four different approaches to achieve this. In this article, we are having a button in our HTML document and our task is to trigger a file download when clicking an HTML button or JavaScript. Approaches to trigger file download Here is a list of approaches to trigger a file download when clicking an HTML button or ...

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