Category: JavaScript tutorial
-
Understanding preventDefault() in JavaScript
What is preventDefault()? The preventDefault() method is part of the Event interface in JavaScript. It is used to cancel the browser’s default behavior associated with a particular event, without stopping the event from bubbling or reaching other event handlers. Syntax Common Use Cases Scenario Default Behavior Why Use preventDefault()? Clicking a link (<a href=”…”) Navigates…
-
Understanding stopImmediatePropagation() in JavaScript
What is stopImmediatePropagation()? The stopImmediatePropagation() method is part of the Event interface in JavaScript. It is used to stop the execution of all remaining event listeners that are registered to the same event target for the same event type. In other words, if you have multiple event listeners for the same event on the same…
-
JavaScript stopPropagation()
In JavaScript, user interactions like clicks or key presses generate events that can travel across multiple layers of the DOM. Sometimes, developers need to control or limit how these events propagate through the DOM tree. One such control is provided by stopPropagation(). What Is Event Propagation? When an event is fired on an element (such…
-
What Is a Service Worker?
A Service Worker is a special type of JavaScript script that acts as a background proxy layer between your web application and the network (internet or cache). It’s part of the Progressive Web App (PWA) stack and is designed to intercept and handle network requests, cache resources, and enable advanced features like offline browsing, push…
-
Web Storage API in JavaScript
1. Introduction The Web Storage API offers a more user-friendly way for browsers to store key-value pairs, serving as an intuitive alternative to cookies. 2. Concepts and usage The two mechanisms within Web Storage are as follows: The Window.sessionStorage and Window.localStorage properties provide access to these storage mechanisms. Each property returns an instance of a…
-
Event flow in JavaScript
1. Introduction Event flow in JavaScript refers to the sequence in which events are propagated through the DOM (Document Object Model) when an event is triggered. Understanding event flow is crucial for handling events efficiently in your web applications. 2. Phases of event flow Event flow consists of three distinct phases: The sequence of these…
-
Managing Browser History with JavaScript
1. Introduction The History API provides access to the browser’s session history through the history global object. It exposes useful methods and properties that let you navigate back and forth through the user’s history, and manipulate the contents of the history stack. Note that the History API is only available on the main thread (Window).…
-
delete operator in JavaScript
1. Introduction The delete operator removes a property from an object. If the property’s value is an object and there are no more references to the object, the object held by that property is eventually released automatically. Because classes are automatically in strict mode, and private properties can only be legally referenced in class bodies,…
-
Data storage and eviction in browsers
1. Introduction Web developers can use a number of technologies to store data in the user’s browser(i.e, on the local disk of the device the user is using to view the website). The amount of data that browsers allow websites to store, as well as the methods they use to handle data deletion when storage…
-
Pure Function in JavaScript
1. Introduction A pure function is a function that adheres to two key principles: Pure functions are a foundational concept in functional programming and are widely appreciated for their simplicity, predictability, and testability. 2. Key Characteristics of Pure Functions 3. Examples of Pure Functions Pure Function: Addition It always returns the same result for the…