Articles on Trending Technologies

Technical articles with clear explanations and examples

How to calculate the difference between two dates in JavaScript?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 2K+ Views

To calculate the difference between two dates in JavaScript, use the getTime() method to get timestamps in milliseconds, then subtract one from the other. Basic Date Difference Calculation The getTime() method returns the number of milliseconds since January 1, 1970. By subtracting two timestamps, you get the difference in milliseconds. var dateFirst = new Date("11/25/2017"); var dateSecond = new Date("11/28/2017"); // time difference in milliseconds var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime()); // days difference var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // display result console.log("Difference: " ...

Read More

How to set the color of the right border with JavaScript?

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

In this tutorial, we will learn how to set the color of the right border with JavaScript. To set the color of the right border in JavaScript, use the borderRightColor property. Set the color of the right border using this property. We can also apply the borderColor property to complete the task. The border is the outline of an HTML element. Border color can be set for different sides using different properties. To set the color of the right border with JavaScript, we have different ways − Using the style.borderRightColor Property ...

Read More

Write a palindrome program in JavaScript so that only alphanumeric values should be allowed?

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 997 Views

A palindrome is a string that reads the same forwards and backwards. When checking palindromes with alphanumeric characters only, we need to ignore spaces, punctuation, and special characters, considering only letters (a-z) and digits (0-9). For example, "A man, a plan, a canal: Panama" becomes "amanaplanacanalpanama" after removing non-alphanumeric characters, which is indeed a palindrome. Basic Palindrome Check Here's a simple approach using string manipulation methods to check if a string is a palindrome: var str = "racecar"; ...

Read More

Return Top two elements from array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 380 Views

We have an array of numbers in JavaScript that contains numbers in an unsorted order. Our job is to write a function that takes in this array of numbers and returns an array of two elements, the top two elements of the array (greatest two elements of the array). We have to do this in one pass i.e., we need to execute this method in linear time like by using only one for loop or if we use ES6 function, we have to make sure to use only one and once and avoid nesting of methods which increases time ...

Read More

Create HTML Document with Custom URL for the document in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you can create an HTML document with a custom URL using document.implementation.createHTMLDocument() and the element. This technique allows you to set a base URL that affects how relative URLs are resolved within the document. How It Works The createHTMLDocument() method creates a new HTML document. By adding a element to the document's head, you establish a base URL that all relative URLs in the document will resolve against. Example Custom Base URL Example ...

Read More

Generate random characters and numbers in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 497 Views

Generating random characters and numbers is a common requirement in JavaScript applications. You can create random strings by combining characters from a predefined set using Math.random(). Setting Up Character Pool First, define a string containing all possible characters you want to include: var storedCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; Basic Random String Generator Here's a function that generates random strings of any specified length: function generateRandomString(size) { var generatedOutput = ''; var storedCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; var totalCharacterSize = storedCharacters.length; ...

Read More

Calculate difference between circumference and area of a circle - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 249 Views

In this tutorial, we'll learn how to calculate the difference between the area and circumference of a circle using JavaScript. This is a common mathematical problem that demonstrates basic geometry calculations and JavaScript functions. Circle Formulas Before we start coding, let's review the formulas: Area of a circle: π × r² Circumference of a circle: 2 × π × r Where r is the radius of the circle and π (pi) is approximately 3.14159. JavaScript Implementation We'll create a function that takes the radius as input and returns the absolute difference between area ...

Read More

What is the maximum size of a web browser's cookies value?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 5K+ Views

The maximum size of cookies varies across different web browsers. Understanding these limitations is crucial for web developers to ensure proper cookie handling and avoid data loss. Browser Cookie Limits Web Browser Maximum Cookies per Domain Maximum Size per Cookie ...

Read More

How to check if a variable is boolean in JavaScript?

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

In JavaScript, determining if a variable is a boolean can be tricky because of type coercion. When using the equality operator (==), JavaScript converts values, so true == "true" returns true even though they're different types. To accurately check boolean types, we need specific methods. Here are three reliable approaches to check if a variable is a boolean: Using the typeof operator Using the strict equality operator (===) Using Object.prototype.toString.call() Using the typeof Operator The typeof operator returns a string indicating the ...

Read More

With JavaScript RegExp search a hexadecimal number character.

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 473 Views

To find a hexadecimal number character with JavaScript Regular Expression, use the \x escape sequence followed by the two-digit hexadecimal value. Syntax \xdd Where dd represents the two-digit hexadecimal value (00-FF) of the character you want to match. Example: Searching for Hexadecimal Character The following example searches for hexadecimal number 53, which represents the character 'S': JavaScript Regular Expression ...

Read More
Showing 18891–18900 of 61,297 articles
Advertisements