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
1 Answer
Reset to default 8It'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++;
}