What does the JavaScript syntax foo: mean?

前端 未结 1 1572
生来不讨喜
生来不讨喜 2020-12-02 02:01

what does the following code meaning? (it is not json - it is code which does not generate error by js interpreter)

foo: 5

The reason for t

1条回答
  •  伪装坚强ぢ
    2020-12-02 02:57

    It's a JavaScript label: documentation here.

    You can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.

    Note that JavaScript has NO goto statement, you can only use labels with break or continue.

    Example usage (from MDN)

    var itemsPassed = 0;
    var i, j;
    
    top:
    for (i = 0; i < items.length; i++){
      for (j = 0; j < tests.length; j++) {
        if (!tests[j].pass(items[i])) {
          continue top;
        }
      }
    
      itemsPassed++;
    }
    

    0 讨论(0)
提交回复
热议问题