- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript finally
JavaScript Errors
JavaScript finally
finallyruns whether the code succeeded or failed.
It is for cleanup that must happen either way.
Hiding a loading spinner is the classic example.
Example
Example
javascript
const steps = [];
try {
steps.push("trying");
null.length;
} catch (error) {
steps.push("caught");
} finally {
steps.push("cleaned up");
}
console.log(steps.join(" "));