Can i use continue and break in an if statement without any loops in JAVASCRIPT?

前端 未结 2 1149
[愿得一人]
[愿得一人] 2021-01-29 16:49

It\'s well-known that break and continue can be used inside a loop:

2条回答
  •  一生所求
    2021-01-29 17:21

    Normally you can't. You can only use return; to discontinue code execution in an if statement.

    Using break;

    if (true) {
      break;
    }
    console.log(1)

    Using continue;

    if (true) {
      continue;
    }
    console.log(1)

提交回复
热议问题