Web Development Articles

Page 289 of 801

How to call a function repeatedly every 5 seconds in JavaScript?

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

In JavaScript, setInterval() allows you to execute a function repeatedly at specified time intervals. To call a function every 5 seconds, you pass the function and 5000 milliseconds as arguments. Syntax setInterval(function, delay); Where function is the function to execute and delay is the time in milliseconds between executions. Basic Example function myFunction() { console.log("Function called at:", new Date().toLocaleTimeString()); } // Call myFunction every 5 seconds (5000 milliseconds) setInterval(myFunction, 5000); Function called at: 2:30:15 PM Function called at: 2:30:20 PM Function called at: 2:30:25 ...

Read More

How to call the key of an object but return it as a method, not a string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 867 Views

In JavaScript, you can call object methods dynamically using bracket notation instead of dot notation. This allows you to access and execute object methods using string keys, which is useful when the method name is determined at runtime. Basic Dynamic Method Access You can use bracket notation obj[key]() to call methods dynamically: const obj = { greet: function() { console.log("Hello!"); }, farewell: function() { console.log("Goodbye!"); ...

Read More

How to remove falsy values from an array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 745 Views

In JavaScript, falsy values are values that evaluate to false in a boolean context. These include false, 0, "", null, undefined, and NaN. Removing falsy values from an array is a common operation that can be accomplished using several methods. What are Falsy Values? JavaScript has six falsy values that evaluate to false when used in boolean contexts: const falsyValues = [false, 0, "", null, undefined, NaN]; console.log("Falsy values:"); falsyValues.forEach(value => { console.log(`${value} is falsy:`, !value); }); Falsy values: false is falsy: true 0 is falsy: true is ...

Read More

How does inline JavaScript work with HTML?

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

In this article, you will understand how inline JavaScript works with HTML. Inline JavaScript represents a code block written in between the tags in an HTML file. The advantage of using inline JavaScript in HTML files is to reduce the round trip of the web browser to the server. What is Inline JavaScript? Inline JavaScript is JavaScript code that is embedded directly within HTML documents using tags. This approach allows you to execute JavaScript without creating separate .js files, making it convenient for small scripts and quick implementations. Example 1: Basic Inline JavaScript Let ...

Read More

How does Promise.all() method differs from Promise.allSettled() method in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 278 Views

In this article, you will understand how Promise.all() method differs from the Promise.allSettled() method in JavaScript. The Promise.all() method takes one or multiple promises as input and returns a single Promise. This returned promise fulfills when all of the input promises are fulfilled. It rejects immediately when any of the input promises is rejected, with this first rejection reason. The Promise.allSettled() method takes one or multiple promises as input and returns a single Promise. This returned promise fulfills when all of the input promises settle (either fulfilled or rejected), returning an array of objects that describe the outcome ...

Read More

How does internationalization work in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 358 Views

In this article, you will understand how internationalization works in JavaScript. Internationalization is the process of preparing software so that it can support local languages and cultural settings. It can include changing the date and time format, changing the metric system format, language format, etc. JavaScript provides the Intl object which contains constructors for locale-sensitive formatting and language-sensitive string comparison. The most commonly used are Intl.DateTimeFormat for dates and Intl.NumberFormat for numbers. Date and Time Formatting Let's understand how to format dates for different locales using Intl.DateTimeFormat: var inputDate = new Date(1990, 2, 25); console.log("The ...

Read More

How does Implicit coercion differ from Explicit coercion in JavaScript?

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

In this article, you will understand how implicit coercion differs from explicit coercion in JavaScript. An implicit coercion is an automatic conversion of values from one datatype to another that JavaScript performs automatically without programmer intervention. An explicit coercion is the deliberate conversion of data type using built-in functions or operators. Implicit Coercion JavaScript automatically converts data types when needed, especially in operations involving different types. let number = 5; let text = "10"; // JavaScript automatically converts number to string let result1 = number + text; console.log("5 + '10' =", result1, typeof result1); ...

Read More

How does Promise.any() method differs from Promise.race() method in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 186 Views

In this article, you will understand how Promise.any() method differs from Promise.race() method in JavaScript. The Promise.any() method resolves when the first promise succeeds (fulfills), ignoring rejections until all promises fail. The Promise.race() method settles when the first promise completes, regardless of whether it succeeds or fails. Promise.any() Method Promise.any() waits for the first successful promise and ignores rejections. If all promises reject, it throws an AggregateError. console.log("Defining three promise values: promise1, promise2 and promise3"); const promise1 = Promise.resolve(1); const promise2 = new Promise((resolve, reject) => { setTimeout(resolve, 200, 'Promise Two'); }); ...

Read More

How many numbers in the given array are less/equal to the given value using the percentile formula in Javascript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

In this article, you will understand how to calculate the percentile of a given value in an array using JavaScript. The percentile tells us what percentage of numbers in the array are less than or equal to a specific value. Percentile Formula We use the following formula to calculate the percentile: Percentile = (n/N) * 100 Where: n = count of values less than or equal to the given value N = total number of values in the array For values equal to our target, ...

Read More

How to Create Dark/Light Mode for a Website using JavaScript/jQuery?

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

Dark mode has become essential for modern websites, as it reduces eye strain and saves battery life on mobile devices. Studies show that 70-80% of users prefer dark mode, making it a crucial feature for user experience. In this tutorial, we'll learn to create a toggle between dark and light themes using JavaScript and jQuery. We'll use CSS classes and DOM manipulation to switch themes dynamically. Syntax The core method for toggling themes uses the classList.toggle() method: document.body.classList.toggle("dark-theme"); This adds the "dark-theme" class if it doesn't exist, or removes it if it does, ...

Read More
Showing 2881–2890 of 8,010 articles
« Prev 1 287 288 289 290 291 801 Next »
Advertisements