Category: JavaScript Tutorial

python tutorials and learn python

Created with Sketch.

JavaScript for…of Loop

JavaScript for…of Loop Summary: in this tutorial, you’ll how to use JavaScript for…of statement to iterate over iterable objects. Introduction to the JavaScript for…of loop ES6 introduced a new statement for…of that iterates over an iterable object such as: Built-in Array, String, Map, Set, … Array-like objects such as arguments or NodeList User-defined objects that implement…
Read more

JavaScript yield

JavaScript yield Summary: in this tutorial, you will learn about the JavaScript yield keyword and how to use it in generator functions. Introduction to the JavaScript yield keyword The yield keyword allows you to pause and resume a generator function (function*). The following shows the syntax of the yield keyword: [variable_name] = yield [expression]; Code…
Read more

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