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

后端 未结 10 1999
栀梦
栀梦 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 16:03

    why you are getting false is you returned in a finally block. finally block should execute always. so your return true changes to return false

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

提交回复
热议问题