In JavaScript, is returning out of a switch statement considered a better practice than using break?

后端 未结 3 2024
太阳男子
太阳男子 2021-01-29 20:37

Option 1 - switch using return:

function myFunction(opt) 
{
    switch (opt) 
    {
        case 1: retur         


        
3条回答
  •  灰色年华
    2021-01-29 21:22

    A break will allow you continue processing in the function. Just returning out of the switch is fine if that's all you want to do in the function.

提交回复
热议问题