js try catch 有无finally区别

function sayHi(){
  try{
    return 11
  }catch(err){
    console.error(err)
  }finally{
    console.log(555)
  }
}

console.log(sayHi()) //先打印555 再打印 11

function sayHi1(){
  try{
    return 11
  }catch(err){
    console.error(err)
  }
  console.log(555)
  
}
console.log(sayHi1()) //只打印 11

 

posted @ 2026-10-23 11:56  howhy  阅读(8)  评论(0)    收藏  举报