Javascript Articles

Page 208 of 534

How to convert a value to a safe integer using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 580 Views

An integer is known to be a safe integer if it can be exactly represented as an IEEE-754 double precision number. A safe integer is an integer in the range -(2^53 - 1) to (2^53 - 1). All these numbers are considered safe integers because they allow one-to-one mapping between mathematical integers and their representation in JavaScript. What is Number.isSafeInteger()? The Number.isSafeInteger() method determines whether a value is a safe integer. It returns true if the value is a safe integer, otherwise false. Syntax Number.isSafeInteger(testValue) Here testValue is the number to check if ...

Read More

How to create dynamic values and objects in JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 9K+ Views

Dynamic values are values assigned to variables whose names are determined at runtime rather than being hard-coded. In JavaScript, we can use dynamic property names in objects, allowing us to create flexible object structures where property names can be changed without modifying the object definition directly. Dynamic objects are particularly useful when you need to create properties based on variables, user input, or computed values. The key technique involves using square brackets [ ] syntax to define property names dynamically. Syntax Following is the syntax to create dynamic values and objects: const key = 'PropertyName'; ...

Read More

How to display a message when a given number is in the range using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 913 Views

In this article, we will check whether a number lies between a range or not and display a message according to the output we get. This feature of JavaScript allows you to put a number validation while creating a form or any other document. Syntax Following is the syntax to check if number is in range and display the message − if (isNaN(number) || number < lower || number > upper) { document.getElementById("output").innerHTML = number + " is not in range"; } else { document.getElementById("output").innerHTML = number + " is ...

Read More

How to pause and play a loop using event listeners in JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 1K+ Views

In this article, we'll learn how to pause and resume a JavaScript loop using event listeners and promises. This technique is useful for creating controllable animations, counters, or any iterative process that needs user interaction. An event listener attaches an event handler to an element, allowing us to respond to user interactions like button clicks. Syntax element.addEventListener(event, function, useCapture); Parameters event − The name of the event (e.g., "click") function − The function to execute when the event occurs useCapture ...

Read More

How to return true if the bottom of the page is visible using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will check if the bottom part of a page is visible or not to the user. We can do this functionality by using the height of the window and the height of the scrolled window. To write this code we need to understand three methods of JavaScript which are given as: scrollY − It is the read-only property of the window, and returns the pixels a document has scrolled vertically. window.scrollY scrollHeight − It is an HTML DOM element and a read-only property of the window. It returns the height of ...

Read More

How to check if the constructor of an object is a JavaScript Object?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 1K+ Views

In this article, we will check whether the constructor of an object is a JavaScript Object. The constructor property of any JavaScript variable returns a reference to the Object constructor function that created the instance object. The value of this property is a reference to the function itself. All objects have the constructor property, and objects created without an explicit constructor function will have a constructor property that points to the fundamental Object constructor type for that object. To check whether the constructor of a provided value is an Object created by the object constructor function, we need ...

Read More

How to check two numbers are approximately equal in JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 718 Views

In JavaScript, determining if two floating-point numbers are "approximately equal" is essential because of precision issues with decimal calculations. We compare the absolute difference between two numbers against a tolerance value called epsilon. Why Use Approximate Equality? Floating-point arithmetic can produce unexpected results: console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false 0.30000000000000004 false The Algorithm We calculate the absolute difference between two numbers and compare it with epsilon (tolerance). If the difference is less ...

Read More

How to create HTML list from JavaScript array?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 10K+ Views

In this tutorial, we will explore multiple ways to create an HTML list from a JavaScript array. While you can manually create HTML lists using ul (unordered list) and li (list item) tags, this becomes impractical when dealing with dynamic data or large arrays. JavaScript provides efficient methods to dynamically generate HTML lists from array data. Let's examine three different approaches to accomplish this task. Method 1: Using the for Loop The simplest approach uses a traditional for loop to iterate through the array and create list items dynamically using createElement() and appendChild(). ...

Read More

How to swap two array elements in JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 5K+ Views

In this tutorial, we explore different approaches to swap two array elements in JavaScript. For example, we can swap the first and second elements of an array: Input: ["first", "second", "third", "fourth", "fifth"] Output: ["second", "first", "third", "fourth", "fifth"] Here we swapped "first" and "second" values of the array. We will explore three different methods to swap array elements: Using a temporary variable Using Array Destructuring (ES6) Using Array splice() Method Using a Temporary Variable ...

Read More

How to Create an Analog Clock using HTML, CSS, and JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will create a functional analog clock using HTML, CSS, and JavaScript. The clock will display the current time with three hands representing hours, minutes, and seconds that move in real-time. Approach Create the clock structure using HTML with three div elements for the hands Style the clock face and hands using CSS positioning and transforms Use JavaScript's Date object to get current time and calculate hand rotations Update the clock every second using setInterval() Understanding the Time Calculations ...

Read More
Showing 2071–2080 of 5,340 articles
« Prev 1 206 207 208 209 210 534 Next »
Advertisements