Is using labels in JavaScript bad practice?

前端 未结 4 1998
遥遥无期
遥遥无期 2020-12-04 23:55

I just found out about using label s in JavaScript, such as:

for (var i in team) {
    if(i === \"something\") {
        break doThis: //Goto the label
    }         


        
4条回答
  •  天命终不由人
    2020-12-05 00:20

    Those are loop breaker identifiers. They are useful if you have nested loops (loops inside loops) and using these identifiers, you can conditionally specify when and which loop to break out from.

提交回复
热议问题