Salesforce JavaScript Developer Practice Exam

Session length

1 / 20

Given two promises, which of the following correctly executes them in sequence?

p1().then(() => p2()).then(result => result);

p1.then((data) => p2(data)).then(result => result);

The correct choice is based on how promises work in JavaScript. Each promise represents an operation that will complete in the future, and you can chain them to ensure they execute in a specific order. The correct answer executes the two promises in sequence by using the `then` method with a callback that passes the result of the first promise to the second.

In option B, after invoking `p1`, the `then` method is used to handle the resolution of the promise. The result from `p1` is passed as an argument to the function that executes `p2`, ensuring that `p2` only begins executing once `p1` has completed. This guarantees that their execution is sequential: `p1` finishes its operation before `p2` starts, and the return value from `p2` can be handled in subsequent `then` methods.

This behavior contrasts with the other options. While A also executes the promises in sequence, it utilizes a function `p1()`, suggesting it's returning a promise from a function call rather than handling an existing promise directly. It's conceptually valid, but only if `p1` is indeed a function returning a promise. Therefore, option A could be correct depending on its context, but

async function getResult() { const data = await p1; return await p2(data); }

async function getResult() { const data = p1; const result = p2(data); }

Next question

Find the option that is right for you!

All options are one-time payments.

$12.50

30 day premium pass

All the basics to get you started

  • Ad-free experience
  • View your previous attempt history
  • Mobile app access
  • In-depth explanations
  • 30 day premium pass access
👑$30.00 $87.50 usd

6 month DELUXE pass (most popular)

Everything with the 30 day premium pass FOR 6 MONTHS! & the ultimate digital PDF study guide (BONUS)

  • Everything included in the premium pass
  • $87.50 usd value for $30.00! You save $57.50!
  • + Access to the ultimate digital PDF study guide
  • + 6 months of premium pass access
  • + Priority support
$12.50 $18.99

Ultimate digital PDF study guide

For those that prefer a more traditional form of learning

  • Available for instant download
  • Available offline
  • Hundreds of practice multiple choice questions
  • Comprehensive content
  • Detailed explanations
Image Description
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy