Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
let resultA, resultB, resultC;
function addAsync(num1, num2) {
    // use ES6 fetch API, which return a promise
//  return fetch(`http://www.example.com?num1=${num1}&num2=${num2}`)
//      .then(x => x.json());
  
    return Promise.resolve(num1 + num2);
}
addAsync(1, 2)
    .then(success => {
        resultA = success;
        return resultA;
    })
    .then(success => addAsync(success, 3))
    .then(success => {
        resultB = success;
        return resultB;
    })
    .then(success => addAsync(success, 4))
    .then(success => {
        resultC = success;
        return resultC;
    })
    .then(success => {
        console.log('total: ' + success)
        console.log(resultA, resultB, resultC)
    });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
chybiepro
0viewers