Front End Technology Articles

Page 416 of 652

How to copy text to the clipboard with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 679 Views

To copy text to the clipboard in JavaScript, we can use both modern and legacy approaches. The modern navigator.clipboard API is recommended, while the older document.execCommand() method provides fallback support. Modern Approach: Using navigator.clipboard API The navigator.clipboard.writeText() method is the modern standard for copying text. It returns a Promise and works asynchronously. button { border: none; ...

Read More

JavaScript clearTimeout() & clearInterval() Method

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

In JavaScript, the clearTimeout() and clearInterval() methods are used to clear timers. When we set a timer using setTimeout() or setInterval() methods, the browser allocates memory to track it. Therefore, we use these methods to release that memory and avoid unnecessary function calls. It is best practice to clear timers when they are no longer needed to prevent memory leaks and unwanted executions. JavaScript clearTimeout() Method The clearTimeout() method clears a timeout that was previously set by setTimeout(). It prevents the scheduled function from executing if called before the timeout completes. Syntax clearTimeout(timeoutID) Parameters ...

Read More

JavaScript program to retrieve clients IP address

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

Internet Protocol address, in short, IP address, is a unique address represented by a string of numbers that identifies a device on the internet or a local network. In JavaScript, we can retrieve a client's IP addresses using 3rd party API services such as ipify or ipapi. We can then further use this information to track user locations, personalize content based on the location, or implement security measures. Understanding Client-Side IP Detection JavaScript running in the browser cannot directly access the client's IP address due to security restrictions. However, we can use external APIs that return the public ...

Read More

How to Compare Two Arrays in JavaScript?

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

In JavaScript, comparing arrays with == or === operators doesn't work as expected because they compare object references, not actual array contents. This article explores multiple effective methods to properly compare two arrays in JavaScript. When we try to compare arrays directly, JavaScript compares memory references rather than the array elements themselves, which typically results in false even for identical arrays. Why Direct Comparison Fails const arr1 = [1, 2, 3]; ...

Read More

JavaScript example for Capturing mouse positions after every given interval

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 407 Views

In this article, we will demonstrate how to capture the mouse position in JavaScript at regular intervals and log or use this data for various purposes. Capturing mouse positions after every given interval refers to a program or functionality where the current position of the mouse pointer is tracked at regular time intervals. This can be useful in scenarios like debugging, interactive applications, or visualizing user movement on a web page. Use Cases Imagine you want to monitor user activity on a web page and record the mouse position every second. This can be useful for: ...

Read More

How can I round a number to 1 decimal place in JavaScript?

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

In this tutorial, we will learn to round a number to a one decimal place in JavaScript. There are various needs to round the float numbers and show particular digits after the decimal point. In our case, we need to show only one digit after the decimal point. However, we will create a customizable function that can round off the number and show the particular number of digits after the decimal point at the end of this tutorial. This example lets users understand the fundamental need to round a number to a single decimal digit. Suppose you are ...

Read More

JavaScript - convert array with null value to string

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 678 Views

In this article, we will learn to convert an array with a null value to a string in Javascript. Handling arrays containing null, undefined, and falsy values in JavaScript is a frequent challenge. The default methods might not behave as expected when converting such arrays to strings, requiring custom solutions for meaningful string representations. Problem Statement Given an array containing null, undefined, empty strings, and other values, the task is to concatenate its elements into a single string while excluding the unwanted values. Following is our array, with some null and undefined values − Input ...

Read More

JavaScript Program to Check if a Given Year is Leap Year

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

To check if a given year is leap year, we have used two approaches in this article. A leap year has 366 days. In every 4th year, an additional day is added to the month of February to synchronize it with the astronomical year. In this article, we are given with two years to check. Our task is to write a JavaScript program to check if a given year is leap year. Leap Year Rules A year is considered a leap year if it follows these rules: Divisible by 4 AND not divisible ...

Read More

How to Find the action Attribute and method of a Form in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In HTML forms, the action and method attributes control where form data is sent and how it's transmitted. JavaScript provides properties to access and modify these attributes dynamically. The action attribute specifies the URL where form data should be sent when submitted, while the method attribute determines the HTTP method used for submission (GET, POST, or dialog). Using the action Property The action property allows you to get or set the form's action attribute value. Syntax // Get action attribute let actionValue = document.getElementById('formID').action; // Set action attribute document.getElementById('formID').action = 'newURL'; ...

Read More

What is the difference between JavaScript undefined and void(0)?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 902 Views

In this article, we will learn the difference between JavaScript undefined and void(0). Though they may appear similar, they serve distinct purposes and can be used in different scenarios. What is JavaScript undefined? undefined means a variable declared, but no value has been assigned. It is a primitive value automatically assigned to variables that have been declared but not initialized. For Example − var demo; console.log(demo); // shows undefined console.log(typeof demo); // shows undefined undefined undefined It is a global property that represents a variable ...

Read More
Showing 4151–4160 of 6,519 articles
« Prev 1 414 415 416 417 418 652 Next »
Advertisements