Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 414 of 652
Function returning another function in JavaScript
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 MoreHow to read a cookie using JavaScript?
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 MoreExports & Imports in JavaScript
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 MoreHow to use named arguments in JavaScript functions?
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 MoreDefault exports vs Named exports in JavaScript
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 MoreHow to add a new element to HTML DOM in JavaScript?
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 MoreHow to detect a mobile device with JavaScript?
In this tutorial, we are going to learn how can we detect a mobile device over which we are working using JavaScript. Approach 1: Using the navigator.userAgent Property To detect a mobile device with JavaScript we are going to use the window navigator object which contains all the information regarding a browser. The property which we will use to detect a mobile device will be the userAgent property which is used to return the user-agent header sent to the server by the browser. The value we receive from this property is the browser name, version, and platform i.e., ...
Read MoreHow to pad a number with leading zeros in JavaScript?
In this tutorial, we will learn how to pad a number with leading zeros in JavaScript. Padding a number can be done in different ways in JavaScript. In this tutorial, we will see the two most popular ways of doing it − Using the String padStart() method Using the Array object constructor and join() method Using the String padStart() Method In JavaScript, the String object's padStart() method is useful to pad a number with leading zeros. It takes two parameters, the first one is the total length of the targeted or ...
Read MoreHow to remove existing HTML elements in JavaScript?
This article discusses how to delete existing HTML elements in JavaScript. To remove HTML elements, you first need to select the element from the document, then use methods like remove() and removeChild() to delete them from the DOM. Using the remove() Method The remove() method directly removes an element from the DOM. It's the simplest approach for modern browsers. Syntax element.remove(); Example Remove Element Example This heading will be removed This paragraph will remain ...
Read MoreHow to check whether a checkbox is checked in JavaScript?
In this tutorial, we will learn to check whether a checkbox is checked in JavaScript. The checkbox is an input type in HTML that works as a selection box. Unlike radio buttons which allow users to select only one value from a group, checkboxes allow users to select multiple values. HTML can add checkboxes to webpages, but JavaScript is needed to add behavior based on whether checkboxes are checked or not. We'll learn to check both single and multiple checkboxes. Check if a Single Checkbox is Selected To check if a checkbox is selected, we access the ...
Read More