What does the JavaScript syntax foo: mean? - Stack Overflow

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

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 the question is as follows. In the arrow function examples there is one that shows the confusion between json and code block syntax:

var func = () => { foo: 1 };

The func() returns undefined and the above code does not fail. I tried to put just the foo: 5 code as the only code in a js module - and it works... I do not know about a ':' operator neither about labels in js.

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 the question is as follows. In the arrow function examples there is one that shows the confusion between json and code block syntax:

var func = () => { foo: 1 };

The func() returns undefined and the above code does not fail. I tried to put just the foo: 5 code as the only code in a js module - and it works... I do not know about a ':' operator neither about labels in js.

Share Improve this question edited Jan 7, 2019 at 15:12 Quentin 945k133 gold badges1.3k silver badges1.4k bronze badges asked Sep 23, 2016 at 8:04 dzilbersdzilbers 3921 gold badge5 silver badges10 bronze badges 2
  • 1 It's a label. That is all. – Niet the Dark Absol Commented Sep 23, 2016 at 8:05
  • Possible duplicate of Return object from arrow function – Tamas Hegedus Commented Sep 23, 2016 at 8:08
Add a ment  | 

1 Answer 1

Reset to default 8

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++;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744272902a4566188.html

相关推荐

  • What does the JavaScript syntax foo: mean? - Stack Overflow

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

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信