1new Promise((resolve, reject) => {
2    console.log('Initial');
3
4    resolve();
5})
6.then(() => {
7    throw new Error('Something failed');
8
9    console.log('Do this');
10})
11.catch(() => {
12    console.error('Do that');
13})
14.then(() => {
15    console.log('Do this, no matter what happened before');
16});
171try {
2  const result = syncDoSomething();
3  const newResult = syncDoSomethingElse(result);
4  const finalResult = syncDoThirdThing(newResult);
5  console.log(`Got the final result: ${finalResult}`);
6} catch(error) {
7  failureCallback(error);
8}
91doSomething()
2.then(result => doSomethingElse(result))
3.then(newResult => doThirdThing(newResult))
4.then(finalResult => {
5  console.log(`Got the final result: ${finalResult}`);
6})
7.catch(failureCallback);
81async function foo() {
2  try {
3    const result = await doSomething();
4    const newResult = await doSomethingElse(result);
5    const finalResult = await doThirdThing(newResult);
6    console.log(`Got the final result: ${finalResult}`);
7  } catch(error) {
8    failureCallback(error);
9  }
10}
111doSomething(function(result) {
2  doSomethingElse(result, function(newResult) {
3    doThirdThing(newResult, function(finalResult) {
4      console.log('Got the final result: ' + finalResult);
5    }, failureCallback);
6  }, failureCallback);
7}, failureCallback);
81doSomething()
2.then(result => doSomethingElse(result))
3.then(newResult => doThirdThing(newResult))
4.then(finalResult => console.log(`Got the final result: ${finalResult}`))
5.catch(failureCallback);
61const promise = doSomething();
2const promise2 = promise.then(successCallback, failureCallback);
31doSomething()
2.then(function(result) {
3  return doSomethingElse(result);
4})
5.then(function(newResult) {
6  return doThirdThing(newResult);
7})
8.then(function(finalResult) {
9  console.log('Got the final result: ' + finalResult);
10})
11.catch(failureCallback);
12