Promise finally in JavaScript

Level 394 keystrokes

finally() is called regardless of whether the promise is fulfilled or rejected.

JavaScript code

// Promise.resolve() creates a resolved promise with value "done"
1Promise.resolve("done")
// then() receives "done" and prints it
2 .then(val => console.log(val))
// finally() runs regardless of success or failure, good for cleanup
3 .finally(() => console.log("cleanup"));

Output

done
cleanup
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • (× 6
  • )× 6
  • .× 5
  • "× 4
  • =× 2
  • >× 2
  • ;× 1

More JavaScript examples at level 3

← JavaScript typing practice