Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 10 of 80

How to Access the Correct "this" Inside a Callback?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 639 Views

In this tutorial, we will learn how to access the correct "this" inside a callback function. This is a common challenge in JavaScript because callback functions can lose their original context. Understanding the "this" Problem in Callbacks The value of "this" in JavaScript depends on how a function is called, not where it's defined. When a function is passed as a callback, it often loses its original context, causing "this" to refer to something unexpected (like the global object or undefined in strict mode). The Problem: Lost Context ...

Read More

How to use array that include and check an object against a property of an object?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

The task is to check whether the array contains a particular value. Also, we need to check if the array contains the particular object with the given property. This tutorial will use the array.includes() and array.some() methods to check whether the array contains the value or object with a particular property. Use the array.includes() method to check values exist in the array The array.includes() method allows us to check whether the array contains any value. In simple terms, we can search for values in the array using the array.includes() method. Syntax array.includes(value, startIndex); ...

Read More

Is it possible to write data to file using only JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 544 Views

In this tutorial, we will learn if it is possible to write data to files using only JavaScript. The short answer is: it depends on the environment. Pure client-side JavaScript running in browsers cannot directly write files to the user's system for security reasons. However, Node.js (server-side JavaScript) provides the fs module for file operations. Browser JavaScript Limitations Client-side JavaScript cannot write files directly due to security restrictions. Browsers prevent web pages from accessing the file system to protect users from malicious scripts. Node.js File Writing Node.js includes the fs (File System) module that handles ...

Read More

How to use await outside of an async function in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In JavaScript, the await keyword can only be used inside async functions. However, there are several techniques to work with asynchronous code when you need to use await at the top level or outside of async functions. Here, we will learn different approaches to handle asynchronous operations outside of regular async functions. Using Immediately Invoked Function Expression (IIFE) The most common approach is to wrap your code in an immediately invoked async function expression. This allows you to use await within the function scope. Syntax (async () => { let ...

Read More

How to use Checkbox inside Select Option using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 9K+ Views

Sometimes, we require to use the checkbox inside the select option. We can allow users to select multiple options by introducing the checkboxes with the select option. However, if we use the multiple attributes with the tag, it allows us to select them by pressing the 'ctrl + left click', but it is a bad UX. So, we can introduce the checkbox inside the menu to improve the user experience. Here, we will use JavaScript to manage the values of the checked checkboxes in the custom menu. Create a Custom Select Menu The ...

Read More

How to check which tab is active using Material UI?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 3K+ Views

Material-UI provides a variety of components that help us build user interfaces with a consistent look and feel. One of the components that Material-UI provides is the Tabs component, which allows us to create tabbed interfaces in our applications. In this tutorial, we will learn how to check which tab is active using Material-UI, a popular React UI library. Use the useState Hook to Check Which Tab is Active Users can follow the steps below to check which tab is active using Material UI. Step 1 − First, users need to install Material-UI. We can do this ...

Read More

How to create half of the string in uppercase and the other half in lowercase?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

To convert half of a string to uppercase and the other half to lowercase, we can use JavaScript's built-in string methods like toUpperCase(), toLowerCase(), and substr() (or substring()). This tutorial demonstrates two effective approaches to achieve this transformation. Using for-loop with toUpperCase() and toLowerCase() This approach uses loops to iterate through the string and convert each character individually based on its position. Syntax for (let i = 0; i < length / 2; i++) { newStr += string[i].toUpperCase(); } for (i = length / 2; i < length; i++) { ...

Read More

How to sort strings in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 28K+ Views

Sorting strings is essential for organizing data alphabetically in JavaScript applications. Whether displaying user lists, organizing menu items, or processing API data, string sorting helps create better user experiences. JavaScript provides built-in methods for sorting, but understanding different approaches helps you choose the right solution for your needs. Using the sort() Method The sort() method is JavaScript's built-in array sorting solution. Unlike other languages that sort numbers by default, JavaScript converts all elements to strings and sorts them alphabetically. Syntax arrayOfStrings.sort(); Basic String Sorting ...

Read More

How to serialize a cookie name-value pair into a Set Cookie header string in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

The cookie allows us to store users' data in the web browser for quick response. For example, when a user opens the profile page in any web application, the web page receives the data from the server. The server also sends the cookies containing the data to store in the web browser. When a user goes on the profile page again, it fetches the data from the cookie rather than fetching it from the server to load the webpage quickly. To get data browser looks in the cookie first, and if it doesn't find data stored in the cookie, ...

Read More

How to show Page Loading div until the page has finished loading?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 12K+ Views

Rather than showing a blank white or black screen while loading the page, it is better to show a loading indicator, which improves the user experience of the application. Nowadays, there are many libraries available to show loading indicators. However, we can use HTML, CSS, and JavaScript to create a customized loading indicator div. In this tutorial, we will use HTML, CSS, and JavaScript to show page loading div until the page has finished loading. Use the onreadystatechange Event to Show the Loading Indicator In JavaScript, the onreadystatechange event triggers whenever the state of the web ...

Read More
Showing 91–100 of 793 articles
« Prev 1 8 9 10 11 12 80 Next »
Advertisements