How to do it...

  1. Open your command-line application and navigate to your workspace.
  2.  Create a new folder named 3-08-simulating-finally.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js file with a main function that logs out messages for before and after promise creation:
export function main() { 
 
  console.log('Before promise created'); 
 
  console.log('After promise created'); 
} 
  1. Create a function named addBoosters that throws an error if its first parameter is false:
function addBoosters(shouldFail) { 
  if (shouldFail) { 
    throw new Error('Unable to add Boosters'); 
  } 
 
  return { 
    boosters: [{ 
      count: 2, 
      fuelType: 'solid' 
    }, { 
      count: 1, 
      fuelType: 'liquid' 
    }] 
  }; 
} 
  1. Use Promise.resolve to pass a Boolean ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.