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
Articles by Shubham Vora
Page 9 of 80
Explain the working of timers in JavaScript
In JavaScript, timers are a very noteworthy feature. As like the normal watch timer, we can start the timer at a time and execute the function or code in JavaScript after a particular time. In simple terms, we can use the timer to execute the code after some delay. For example, when you visit some website, it shows the signup box after 3 to 4 minutes of your visit, and that we can achieve using JavaScript. We can set the delay timer to show the signup popup box. Another good example of the timer in real life is ...
Read MoreExplain the different ready states of a request in AJAX
AJAX stands for Asynchronous JavaScript and XML. It is a set of web development techniques to create interactive web applications. AJAX allows a web page to communicate with a server without reloading the page. Ready states are an important part of working with AJAX requests. The ready state of a request indicates the request's status to the server and allows the client to track the progress of the request through the readyState property of the XMLHttpRequest object. In the below sections, we detail the different ready states of AJAX requests. UNSENT STATE (0) This is the ...
Read MoreExtract a number from a string using JavaScript
In JavaScript, there are multiple ways to extract a number from a string. One way is to use the match() method and a regular expression to search for all numeric digits in the string. Another way is to use the replace() method and a regular expression to remove all nonnumeric characters from the string, leaving only the numbers. Let's understand each of the methods with the help of some examples. Using the match() method and regular expression The regular expression is one kind of search pattern which we can create by combining multiple alphabetic and special characters. ...
Read MoreHow to Create and Save text file in JavaScript?
In this tutorial, we will learn to create and save text files in JavaScript. Sometimes, developers need to get text content from users and allow them to store it in a text file that can be downloaded to their local computer. JavaScript provides native methods to achieve this, and we can also use third-party libraries like FileSaver.js for enhanced functionality. Create a Text File Using Native JavaScript We can use native JavaScript operations to create and save text files on the user's computer. The approach uses the HTML tag with the Blob API to create downloadable ...
Read MoreHow to Create Dark/Light Mode for a Website using JavaScript/jQuery?
Dark mode has become essential for modern websites, as it reduces eye strain and saves battery life on mobile devices. Studies show that 70-80% of users prefer dark mode, making it a crucial feature for user experience. In this tutorial, we'll learn to create a toggle between dark and light themes using JavaScript and jQuery. We'll use CSS classes and DOM manipulation to switch themes dynamically. Syntax The core method for toggling themes uses the classList.toggle() method: document.body.classList.toggle("dark-theme"); This adds the "dark-theme" class if it doesn't exist, or removes it if it does, ...
Read MoreHow to create a dropdown list using JavaScript?
We will learn to create a dropdown list using HTML and JavaScript below. Before starting with the article, let's understand the dropdown list and why we need to use it. The dropdown list gives multiple choices to users and allows them to select one value from all options. However, we can do the same thing using multiple radio buttons, but what if we have hundreds of choices? Then we can use the dropdown menu. When users click the dropdown button, it opens all the choices, and users can select anyone. Also, the dropdown provides a better user experience ...
Read MoreHow to create a dynamic length array with numbers and sum the numbers using JavaScript?
In JavaScript, arrays are always dynamic in length. Unlike some programming languages, we don't need to define the array's length while creating it. We can create an array and push whatever number of elements we want. Here, we will create a dynamic length array with numbers and sum all its elements. Using For Loop to Sum Array Elements We can iterate over the array using a for loop and add every element to get the sum. Let's look at both traditional for loops and for-of loops. Syntax let arraySum = 0; for (let i = ...
Read MoreHow to create a hash from a string in JavaScript?
Before we start, let's understand the hash in JavaScript. The hash is also a string, but it's encrypted using a particular algorithm. Generally, we use the hash for security purposes. For example, Google stores users' emails and passwords in their database. Now, Google's employees can access their database for development purposes. But can they get the user's email and password from the database? No, because the password is stored in the hash form, and to decrypt the password, the employee needs the key which we used while creating the hash from the password string. So, in such a ...
Read MoreHow to Create Query Parameters in JavaScript?
Query parameters are key-value pairs appended to URLs after a question mark (?). They're essential for passing data between web pages, implementing search functionality, and creating dynamic URLs. For example, when you search on Amazon, your search term becomes a query parameter in the URL. JavaScript provides several methods to create query parameters programmatically. This is useful when building search features, filtering options, or any functionality that needs to modify URLs based on user input. Using encodeURIComponent() Method The encodeURIComponent() method encodes special characters in URL components. For example, spaces become %20, and other special characters are ...
Read MoreHow to stop forEach() method in JavaScript?
In JavaScript, programmers can use the forEach() method to iterate through array elements. We can call a callback function, which we pass as a parameter of the forEach() method for every array element. Sometimes, we may need to stop the forEach() loop after executing the callback function for some elements. We can use the 'break' keyword with a normal loop to stop it: for(let i = 0; i < length; i++){ // code if(some condition){ break; } } However, we ...
Read More