Why does a return in `finally` override `try`?

后端 未结 10 2017
栀梦
栀梦 2020-12-12 15:22

How does a return statement inside a try/catch block work?

function example() {
    try {
        return true;
    }
    finally {
        return false;
             


        
10条回答
  •  佛祖请我去吃肉
    2020-12-12 15:56

    Returning from a finally-block

    If the finally-block returns a value, this value becomes the return value of the entire try-catch-finally statement, regardless of any return statements in the try and catch-blocks

    Reference: developer.mozilla.org

提交回复
热议问题