JavaScript finally Statement
You are Here:
JavaScript finally Statement
The finally
statement defines a block of code that will execute whether or not an exception was thrown.
Note: The finally
statement can’t appear on its own; it must be after a try block.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="point"></p>
<p id="point1"></p>
<script>
var x = document.getElementById("point");
var y = document.getElementById("point1");
var z = document.getElementById("point2");
function myFunction(){
try{
x.innerHTML = bike;
}
catch(e){
x.innerHTML= e.message;
return;
}
finally{
y.innerHTML = "I will always execute";
}
z.innerHTML = "I will not execute";
}
myFunction();
</script>
</body>
</html>
Syntax
try{
// code block to try
}catch(e){
// code block to handle errors
}finally{
// code block always execute
}
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.