Found 8591 Articles for Front End Technology

Various ways to define a variable in JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:42:52

835 Views

In this article, we will learn about the various ways to define and declare variables in javascript, and how we can use them to implement state management in our applications. In javascript, variables can be thought of as containers that hold values, and which can be retrieved later on in the application. There are several ways to define a variable, each with its own syntax and use cases. Let’s understand different methods of doing so with the help of some examples to understand the concept better. Example 1: Using the var keyword The “var” variable has function scope, which means ... Read More

How to read a cookie using JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:40:37

5K+ Views

In this article, we will learn how to read cookies in javascript, and how we can use it to implement certain features such as user tracking, user preference, personalized experience, etc. Cookies are small pieces of data stored in a user's web browser. In javascript, we can read cookies using document's cookie property and extract the desired information using destructuring. Let’s look at some of the examples to understand the concept better − Example 1 - Reading All Cookies In this example, we will − read all cookies by accessing the document.cookie property and log them to the console. ... Read More

Function returning another function in JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:37:40

681 Views

In JavaScript, functions can be assigned to any variables, they can be passed as arguments to other functions, and can even be returned from other functions. This behavior of functions allow us create HOCs in javascript, which are functions that return other functions. These higher−order functions can be used in various applications like callback functions, function memoization, or transformation, etc. In this article, we will learn functions returning another function, aka higher−order functions in javascript, and how we use them to implement certain javascript features like callbacks, array/object filtering and transformations, etc. Let’s look at some of the examples to ... Read More

How to add delay in a loop in JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:20:32

5K+ Views

Loops are used in JavaScript to repeat actions or iterate over a piece of data. With the aid of various techniques, we can add a delay between each iteration of the loop in order to regulate the speed of execution or produce particular temporal effects. This article will teach you how to include a delay in a java script loop and how to use it to delay the execution of a specific piece of code that is running inside one. Let’s look at some of the examples to understand the concept better − Example 1 - Using setTimeout() In the ... Read More

Program to check/uncheck checkboxes using JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:14:47

527 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 the web page Checboxes are one of the most used HTML elements in forms and user interfaces that allow users to pick numerous options. In JavaScript, we can dynamically check or uncheck checkboxes based on certain conditions or user interactions. Let’s look at some of the examples to understand the concept better − Example 1 In this example, we will − We will create 3 different checkboxes, a checkAll() and ... Read More

JavaScript program to retrieve clients IP address

Shriansh Kumar
Updated on 08-Oct-2024 17:20:26

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 a 3rd parties 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. Using "ipify" API To obtain the client's IP address, we will use a third−party API service (https://www.ipify.org/). We'll send a GET call to the "ipify" API using the $.getJSON() function to ... Read More

How to toggle a boolean using JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:08:11

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 NOT operator, ... Read More

Creating auto-resize text area using JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:05:39

955 Views

In this post, we are going to learn how to set up an auto−size text area in JavaScript. This text area will be able to change its height automatically depending on the content within it. Auto−size 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 dynamically ... Read More

Location protocol Property in JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:03:36

233 Views

This article will teach us how to use the Javascript location protocol properties to implement the web application's protocol. The read−only location.protocol property in javascript returns the protocol specified in the current webpage's URL. It offers details on the URL's protocol, including "http:", "https:", "file:", etc. Common protocol values that are utilised by numerous web apps include − http − It represents the Hypertext Transfer Protocol (HTTP). https − It represents the Hypertext Transfer Protocol Secure (HTTPS). file − It represents the File Transfer Protocol (FTP). ftp − It represents the File Transfer Protocol (FTP). data − It represents the data ... Read More

PreventDefault( ) vs Return false in JavaScript?

AmitDiwan
Updated on 16-Aug-2023 14:59:37

3K+ Views

In this post, we will discover how to use javascript's preventDefault and return false functions to override an event's default behaviour. The two most popular JavaScript methods for stopping an event's default behaviour are preventDefault() and return false. Let’s understand both of the concepts below − preventDefault() Return false The preventDefault() method is a function available on event objects in JavaScript Return false is not a function, but a javascript statement It helps to stop a certain event's default behaviour. It not only prevents the default behavior but also stops the event from ... Read More

Advertisements