Sunday, 9 December 2018

JavaScript: What is the behavior, if finally block returns a value

HelloWorld.js
function get_value(){
  try{
    return 10;
  }catch(e){
    return 20;
  }finally{
    return 30;
  }
}

console.log(get_value());

What is the output of above program?
If a finally block returns a value, then the value returned by finally block is the return value for entire try-catch-finally block.

In the above example, 30 is printed to console.

Previous                                                 Next                                                 Home

No comments:

Post a Comment