Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the state of the promise object in es6

Shulou Source: shulou.com Published: 2022-06-01 02:00:06 09月11日 Update

This article mainly introduces the relevant knowledge of "what is the state of promise objects in es6". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what is the state of promise objects in es6" can help you solve the problem.

Status: 1. The state of pending in progress, which is initialized, but there is no result in the process; 2. If fulfilled is successful, resolved status will trigger subsequent then callback functions; 3. Rejected failure status, rejected status will trigger subsequent catch callback functions.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What are the states of promise objects in es6

Three states

1.pending: there are no results in the process

2.resolved: success

3.rejected: failed

State change

1. Pending-> resolved

2. Pending-> rejected

The expression of state

Pending status does not trigger then and catch

The resolved status triggers subsequent then callback functions

The rejected status triggers subsequent catch callback functions

Then and catch change state

Then normally returns resolved, and returns rejected if an error is reported.

Catch normally returns resolved, and returns rejected if an error is reported.

Test questions

/ / the first question (the result will be printed out 1 minute 3 Returns the resolved status) Promise.resolve () .then (() = > {console.log (1) / / 1 resolved}) .catch (() = > {console.log (2)}) .then (() = > {console.log (3) / / 3 resolved}) / / the second question (the result will be printed out) 3) Promise.resolve (). Then (() = > {console.log (1) / / 1 throw new Error ("error1") / / rejected}). Catch () = > {console.log (2) / / 2 resolved}). Then (() = > {console.log (3) / / 3 resolved}) / / third question (the result will print out 1) Promise.resolve.then (() = > {console.log (1)) / / 1 throw new Error ("error1") / / rejected}) .catch (() = > {console.log (2) / / 2 resolved}) .catch (() = > {console.log (3)})

This is the end of the content about "what is the status of promise objects in es6". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Status results objects functions knowledge process success situation industry different practical content practical practical tutorials articles methods more cases test questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker NVidia vpn Shulou Information