Blog

python tutorials and learn python

Created with Sketch.

JavaScript Generators

JavaScript Generators Summary: in this tutorial, you will learn about JavaScript Generators and how to use them effectively. Introduction to JavaScript Generators In JavaScript, a regular function is executed based on the run-to-completion model. It cannot pause midway and then continues from where it paused. For example: function foo() { console.log(‘I’); console.log(‘cannot’); console.log(‘pause’); } Code…
Read more

The Essential Guide to JavaScript Iterators

The Essential Guide to JavaScript Iterators Summary: in this tutorial, you will learn about JavaScript iterator and how to use iterators to process a sequence of data more efficiently. The for loop issues When you have an array of data, you typically use a for loop to iterate over its elements. For example: let ranks =…
Read more

JavaScript async/await

JavaScript async/await Summary: in this tutorial, you will learn how to write asynchronous code  using JavaScript  async/  await keywords. Note that to understand how the async / await works, you need to know how promises work. Introduction to JavaScript async / await keywords In the past, to deal with asynchronous operations, you often used the…
Read more

Promise Error Handling

Promise Error Handling Summary: in this tutorial, you will learn how to deal with error handling in promises. Suppose that you have a function called getUserById() that returns a Promise: function getUserById(id) { return new Promise((resolve, reject) => { resolve({ id: id, username: ‘admin’ }); }); } Code language: JavaScript (javascript) Normal error First, change…
Read more

JavaScript Promise finally()

JavaScript Promise finally() Summary: in this tutorial, you will learn how to use the JavaScript Promise finally() method to execute the code once the promise is settled, regardless of its outcome. Introduction to the JavaScript Promise finally() method Suppose that you have a promise: promise .then(result => { …}) .catch(error => { … }) .finally(()…
Read more

JavaScript Promise.allSettled()

JavaScript Promise.allSettled() Summary: in this tutorial, you’ll learn about the Promise.allSettled() method to compose promises. Introduction to the Promise.allSettled() method ES2020 introduced the Promise.allSettled() method that accepts a list of Promises and returns a new promise that resolves after all the input promises have settled, either resolved or rejected. The following shows the syntax of…
Read more

JavaScript Promise.any()

JavaScript Promise.any() Summary: in this tutorial, you’ll learn how to use the JavaScript Promise.any() method to compose promises. Introduction to JavaScript Promise.any() method The Promise.any() the method accepts a list of Promise objects as an iterable object: Promise.any(iterable); Code language: JavaScript (javascript) If one of the promises in the iterable object is fulfilled, the Promise.any()…
Read more

JavaScript Promise.race()

JavaScript Promise.race() Summary: in this tutorial, you will learn how to use the JavaScript Promise.race() static method. Introduction to JavaScript Promise.race() static method The Promise.race() static method accepts a list of promises as an iterable object and returns a new promise that fulfills or rejects as soon as there is one promise that fulfills or rejects,…
Read more

JavaScript Promise.all()

JavaScript Promise.all() Summary: in this tutorial, you will learn how to use the Promise.all() static method to aggregate results from multiple asynchronous operations. Introduction to the JavaScript Promise.all() method The Promise.all() static method takes an iterable of promises: Promise.all(iterable); Code language: JavaScript (javascript) The Promise.all() method returns a single promise that resolves when all the…
Read more

Promise Chaining

Promise Chaining Summary: in this tutorial, you will learn about the JavaScript promise chaining pattern that chains the promises to execute asynchronous operations in sequence. Introduction to the JavaScript promise chaining Sometimes, you want to execute two or more related asynchronous operations, where the next operation starts with the result from the previous step. For…
Read more