Front End Technology Articles

Page 333 of 652

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

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 perform integer division and get the remainder in JavaScript?

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

In JavaScript, performing integer division and getting the remainder requires different operators than regular division. The division operator (/) returns a floating-point result, while the remainder operator (%) gives you what's left after division. The remainder operator (%) returns the remainder when one operand is divided by another. It always takes the sign of the dividend (the first operand). For the operation x % y, x is the dividend and y is the divisor. Understanding Division vs Remainder Regular division in JavaScript returns decimal results, but for integer division, we need to use Math.floor() or other methods ...

Read More

How to get a number of days in a specified month using JavaScript?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 1K+ Views

To get the number of days in a specified month in JavaScript, you can use the Date constructor with a clever trick: create a date for the first day of the next month, then subtract one day to get the last day of the target month. The Date Constructor Trick The key insight is that new Date(year, month, 0) returns the last day of the previous month. Since JavaScript months are zero-indexed (0 = January, 1 = February, etc.), passing the actual month number gives us the last day of that month. Basic Implementation ...

Read More

How do you check that a number is NaN in JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 369 Views

NaN is a JavaScript property representing "Not-a-Number" value. It indicates that a value is not a legal number. JavaScript provides two methods to check for NaN values: Number.isNaN() and the global isNaN() function. Syntax Number.NaN Number.isNaN(value) isNaN(value) Using Number.isNaN() (Recommended) Number.isNaN() is the most reliable method as it only returns true for actual NaN values without type coercion: Check with Number.isNaN() function display() { ...

Read More

How to round up a number in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 1K+ Views

In JavaScript, the Math.ceil() method rounds a number up to the nearest integer. Unlike regular rounding, it always rounds upward, making it useful for scenarios like calculating pages needed or ensuring minimum values. Syntax Math.ceil(x) Where x is the number to round up. The method returns the smallest integer greater than or equal to x. How Math.ceil() Works If the number is already an integer, it returns the same number If the number has any decimal part (even 0.1), it rounds up to the next integer ...

Read More

How to find the largest number contained in a JavaScript array?

Abhishek
Abhishek
Updated on 15-Mar-2026 12K+ Views

In this tutorial, we will learn about the different methods to find the largest number contained inside a JavaScript array. An array is a collection of different values, and we need efficient ways to identify the maximum value. There are three main approaches to find the largest number in a JavaScript array: Traversing the Whole Array Using the reduce() Method Using the Math.max() and apply() methods Using Array Traversal (For Loop) This is the most straightforward approach where we iterate through each element and compare it with the current largest value. Algorithm Steps ...

Read More

How to convert a String containing Scientific Notation to correct JavaScript number format?

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

In JavaScript, scientific notation strings like "7.53245683E7" can be converted to regular numbers using several methods. The most straightforward approach is using the Number() function. Using Number() Function The Number() function converts scientific notation strings to decimal numbers: document.write("String with Scientific Notation converted below:"); document.write(Number("7.53245683E7")); String with Scientific Notation converted ...

Read More

How to compare two numbers in JavaScript?

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

In this tutorial, we will learn to compare two numbers in JavaScript. Whether you're a competitive coder or application developer, you'll often need to compare numbers and perform operations based on the comparison results. Many programmers think we can only compare numbers using equality operators, but we can also use less than () operators for comprehensive comparisons. Using the Strict Equality Operator (===) JavaScript has two equality operators: loose equality (==) and strict equality (===). The strict equality operator compares both value and data type, making it more reliable for number comparisons. Syntax let ...

Read More

How to remove leading zeros from a number in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 21K+ Views

In this tutorial, we will explore how we can remove leading zeroes from any number in JavaScript. JavaScript removes leading zeroes from an integer variable automatically, but this is not the case when we consider strings in JavaScript. It is possible that a string in JavaScript which represents a numerical value may contain leading zeroes. These leading zeroes may cause problems when we try to perform any operation on the numerical value the string represents. This is why we will explore the ways by which we can remove the leading zeroes from a number, expressed as a string in ...

Read More
Showing 3321–3330 of 6,519 articles
« Prev 1 331 332 333 334 335 652 Next »
Advertisements