Found 6710 Articles for Javascript

How to create Covid19 Country wise status project using REST API?

Shubham Vora
Updated on 28-Feb-2023 17:28:35

361 Views

Before creating the project, we will first discuss REST API. REST is a software architecture style and a collection of standards that helps make online services. Representational State Transfer is the full name of REST. At the same time, Application programming interfaces (API) allow communication between two or more computer programmes. It is a software interface that gives other software programmes a service. The user must follow the rules known as a REST API based on the HTTP (Hypertext Transfer Protocol) to access web services. Conventional HTTP methods like GET, POST, PUT, and DELETE access and modify resources like ... Read More

How to write shorthand for document.getElementById() method in JavaScript?

Shubham Vora
Updated on 28-Feb-2023 17:27:44

1K+ Views

The document.getElementById() method allows us to access any HTML element using its id in JavaScript. Every webpage can contain only a single HTML element with a single id. You can use the below example code to access any HTML element using its id. let element = document.getElementById('id'); In the above code, we used the getElementById() method of the document object and passed the id as a parameter. Now, if we require to access multiple elements using their id, it is not a good idea to use a document.getElementById(), but we can create a shorthand for it and ... Read More

How to write an inline IF statement in JavaScript?

Shubham Vora
Updated on 28-Feb-2023 17:23:39

8K+ Views

Conditional statements are the most important and basic concept of any programming language. The if-else statement allows us to execute any code block conditionally. We can define the condition for the if statement in braces, and if the condition becomes true, it executes the code of the if block; Otherwise, it executes the code of the else block. Here, we have demonstrated how an if-else statement works in JavaScript. if (condition) { // code to execute when the condition becomes true } else { // ... Read More

How to write a simple code of Memoization function in JavaScript?

Shubham Vora
Updated on 01-Mar-2023 10:46:23

408 Views

Memoization is the optimization technique to improve the performance of the function. Before we start with the memoization technique, let’s understand why we require it using the example below. Example (Naïve approach to finding Fibonacci number) In the example below, we have implemented the naïve approach to find the nth Fibonacci number. We used the recursive approach to find the nth Fibonacci series. Finding the nth Fibonacci using recursive approach number in JavaScript Enter the number to find the nth Fibonacci number. ... Read More

How to write a cell phone number in an international way using JavaScript?

Shubham Vora
Updated on 28-Feb-2023 17:21:18

655 Views

When you have visitors from worldwide on your websites, it is a good idea to show things like a cell phone number according to international standards. So they can easily understand. We can use the International Public Telecommunication Numbering Format to represent the cell phone number in an international way. Also, it is represented by the ‘E-164’ format. We have given the syntax below to follow to write a cell phone number in an international way. [+] [country code] [local phone number] Users can see that the international phone number contains ‘+’ initially and ‘country ... Read More

How to wrap setTimeout() method in a promise?

Shubham Vora
Updated on 28-Feb-2023 17:20:12

8K+ Views

The setTimeOut() method executes some block of code or functions after a particular number of milliseconds. Sometimes, we require to resolve or reject the promise after a particular delay, and we can use the setTimeout() method with the promises. In JavaScript, a promise is an object that returns the result of the asynchronous operation. Here, we will learn to resolve or reject promises after some delay using the setTimeOut() method. Example 1 (Promises without setTimeOut() method) In the example below, we have used the Promise() constructor to create a new promise. The promise constructor takes a callback ... Read More

How to wait resize end event and then perform an action using JavaScript?

Shubham Vora
Updated on 28-Feb-2023 17:18:50

3K+ Views

Whenever we resize the web page window, it triggers the ‘resize’ event by default. The ‘resize’ event triggers multiple times while resizing the window. Sometimes, we require to execute some JavaScript code only once when resize event completes. In such cases, we must use the setTimeOut() method with the resize event to execute JavaScript code or function once the event completes. Also, we require to use the clearTimeOut() method. Syntax Users can follow the syntax below to wait resize event completes and then perform an action using JavaScript. window.addEventListener('resize', () => { ... Read More

How to view array of a structure in JavaScript?

Shubham Vora
Updated on 28-Feb-2023 17:17:38

408 Views

The easiest way to debug the JavaScript code is using the console.log(), which many developers use. Sometimes, we require to know the array's structure and stored values for the debugging purpose. In this tutorial, we will learn to view the array of structures. Various methods of JavaScript allow us to check the structure of the array. For example, we can know if the array contains an object, nested array, string, number or Boolean values. Use the JSON.stringify() Method The JSON.stringify() method allows us to convert the JSON objects into the string. An array is also an object ... Read More

How to use polyfill in JavaScript?

Shubham Vora
Updated on 01-Mar-2023 10:38:38

2K+ Views

The developers of JavaScript always keep adding new features to the JavaScript language to improve performance and add better functionalities. Sometimes, it happens that new features don’t support by the old browser versions. For example, the exponential operator is introduced in ES7, and the trailing comma in the object is also valid in ES7. Now, while developing the application, we have added used the exponential operator in the application. It will work with the newer versions of the browser, but if someone is using a very old version of the browser, they can get errors like the exponential operator is ... Read More

Hot Reload in ElectronJs

Shubham Vora
Updated on 28-Feb-2023 16:42:28

5K+ Views

Hot reloading is a powerful feature in ElectronJS that lets developers quickly view their code changes in real time without having to restart the application. It makes the development process faster and more efficient by reducing the time and effort required to test changes. Steps to Implement Hot Reload in ElectronJS The hot reloading feature is implemented using a library called “electron-reload”, and it can be easily integrated into an Electron JS application by following a few simple steps. Users can follow the steps below to implement hot reload in Electron Js − Install the electron-reload module The first step ... Read More

Advertisements