Standard built-ins

Promise

Try the free JavaScript compiler

Represents eventual completion or failure. The executor runs during construction; the resolver functions select the outcome and cannot change it on repeated calls. Promise reactions execute later.

Formal Syntax & Structure

javascript syntaxjavascript
new Promise((resolve, reject) => { /* start work */ })

Parameters & Attributes

NameTypeDescription
executorfunctionReceives resolve and reject functions.

Return Value

Promise

A newly constructed promise.

Working Example

Example Snippetjavascript
const p = new Promise(resolve => { console.log("executor"); resolve(4); });p.then(n => console.log(n));console.log("after");
JavaScript Reference