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
Javascript Articles
Page 489 of 534
Location protocol Property in JavaScript
The location.protocol property in JavaScript returns the protocol scheme of the current webpage's URL, including the colon (:). It's a read-only property that helps identify whether a page is served over HTTP, HTTPS, or other protocols. Syntax location.protocol Return Value Returns a string representing the protocol scheme, including the trailing colon. For example: "https:", "http:", "file:", etc. Common Protocol Values http: − Hypertext Transfer Protocol (unsecured) https: − Hypertext Transfer Protocol Secure (secured with SSL/TLS) file: − Local file system access ...
Read MoreCreating auto-resize text area using JavaScript
In this post, we are going to learn how to set up an auto-resize text area in JavaScript. This text area will be able to change its height automatically depending on the content within it. Auto-resize text in JavaScript is a helpful feature that can be used to edit multiple lines of text. The text can automatically change its height depending on the content inside it. The default behavior of textarea doesn't allow this, but we can create it by using the input event listener over it. Let's understand how to adjust the height of the text area element ...
Read MoreHow to toggle a boolean using JavaScript?
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 MoreProgram to check/uncheck checkboxes using JavaScript
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 MoreHow to add delay in a loop in JavaScript?
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 MoreHow to convert Array to Set in JavaScript?
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 MoreFunction 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 More