Web Development Articles

Page 509 of 801

How to toggle a boolean using JavaScript?

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

In this tutorial, we will learn how to toggle a boolean value in JavaScript. In addition to this, we will also learn how we can use it for various web application features that require toggling a certain piece of state or value. Toggling a boolean in JavaScript entails altering its value from true to false or vice versa. Toggling booleans can be helpful in a variety of situations, such as changing a boolean value to initiate an action or to toggle between states or the visibility of an element. Toggling can be implemented using different methods like the ...

Read More

Program to check/uncheck checkboxes using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 701 Views

We will learn how to check or uncheck checkboxes in JavaScript in this article, and how we can use it to allow users to make multiple selections on web pages. Checkboxes are one of the most used HTML elements in forms and user interfaces that allow users to pick multiple options. In JavaScript, we can dynamically check or uncheck checkboxes based on certain conditions or user interactions. Let's look at some examples to understand the concept better: Basic Check All/Uncheck All In this example, we will: Create 3 different checkboxes with ...

Read More

How to add delay in a loop in JavaScript?

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

Loops are used in JavaScript to repeat actions or iterate over data. Adding delays between iterations helps control execution speed, create animations, or prevent overwhelming the browser. This article demonstrates how to add delays in JavaScript loops using different techniques. Let's explore practical examples to understand the concept better. Using setTimeout() with Recursive Functions The setTimeout() approach uses recursion to process each array element with a delay: function delayedLoop() { var items = [1, 2, 3, 4, 5]; var delay = 1000; // 1 second ...

Read More

How to convert Array to Set in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 914 Views

This tutorial will teach you how to eliminate duplicate values from an array by converting it to a Set in JavaScript. Sets are collections that store only unique values. When you need to remove duplicates from an array or leverage the unique properties of Sets, converting an array to a Set is the most efficient approach. Using the Set Constructor (Recommended) The Set constructor accepts any iterable object, including arrays, and automatically removes duplicate values. Convert Array to Set - Using Set Constructor ...

Read More

Function returning another function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 796 Views

In JavaScript, functions can be assigned to variables, passed as arguments to other functions, and returned from other functions. This behavior allows us to create higher-order functions (HOFs), which are functions that return other functions. These higher-order functions enable powerful patterns like callbacks, function memoization, and data transformation. In this article, we will learn about functions returning other functions in JavaScript and explore practical examples of their usage. Basic Function Returning Function A function that returns another function creates a closure, where the inner function has access to the outer function's variables: function createGreeter(greeting) { ...

Read More

How to read a cookie using JavaScript?

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

In this article, we will learn how to read cookies in JavaScript and use them for features like user tracking, user preferences, and personalized experiences. Cookies are small pieces of data stored in a user's web browser. In JavaScript, we can read cookies using the document's cookie property and extract specific values using string manipulation techniques. Understanding document.cookie The document.cookie property returns all cookies as a single semicolon-separated string. Each cookie appears as name=value pairs. Example 1: Reading All Cookies This example demonstrates how to access all cookies stored for the current domain: ...

Read More

Exports & Imports in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 471 Views

JavaScript exports and imports enable modular development by allowing us to organize code into reusable modules. This feature helps break down large applications into smaller, maintainable pieces that can be shared across different parts of your codebase. Exports make functions, variables, objects, or any values available outside of a module, while imports bring exported components from other modules into the current module. JavaScript supports two main types of exports: named exports and default exports. Named Exports and Imports Named exports allow you to export multiple components from a single module. Each export must be explicitly named when ...

Read More

How to use named arguments in JavaScript functions?

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

In this article, we will learn how to use named arguments in JavaScript, and how we can use it to significantly enhance code readability and maintainability. JavaScript allows us to simulate named arguments, which eliminate the need for the order of parameters to matter during function execution. We can then access the arguments by name inside the function definitions. Let's look at some of the examples and methods to understand the concept better: What are Named Arguments? Named arguments allow you to pass parameters to a function by explicitly specifying the parameter name rather than relying ...

Read More

Default exports vs Named exports in JavaScript

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

In this article, we will learn the difference between default exports and named exports in JavaScript, and how we can use them to effectively organize our code structure. In JavaScript, we can use default exports and named exports to have separate files or modules for separate pieces of code. This helps in enhancing code readability and tree shaking to a great extent. Default exports Named exports A ...

Read More

How to add a new element to HTML DOM in JavaScript?

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

In JavaScript, adding new elements to the HTML DOM involves creating elements and inserting them into the document structure. This process requires understanding three key methods: createElement(), createTextNode(), and appendChild(). Core Methods for DOM Manipulation The Document object provides essential methods for creating and adding elements to the DOM: document.createElement(tagName) - Creates a new HTML element document.createTextNode(text) - Creates a text node appendChild(element) - Adds an element as the last child insertBefore(newElement, referenceElement) - Inserts an element before a reference element Syntax // Create element const element = document.createElement(tagName); // Create ...

Read More
Showing 5081–5090 of 8,010 articles
« Prev 1 507 508 509 510 511 801 Next »
Advertisements