menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

What happe...
source image

Dev

2w

read

82

img
dot

Image Credit: Dev

What happens when both try and finally return in JavaScript?

  • In JavaScript, when both try and finally blocks have return statements, the finally block will always take precedence over the try and catch blocks.
  • The return statement in a try block does not immediately exit the function. Instead, it creates a Completion Record that is kept internally by the JavaScript engine.
  • The finally block is always executed, regardless of whether there was an error in the try block or an exception caught in the catch block.
  • If the finally block includes a return statement, it will override any previous return statements from the try or catch blocks, and becomes the final return value of the function.

Read Full Article

like

4 Likes

For uninterrupted reading, download the app