Skip to content Skip to sidebar Skip to footer

Labeled Statement - Incorrect Definition?

For JavaScript's label syntax, JS MDN states: label : statement label: Any JavaScript identifier that is not a reserved word. statement: A JavaScript statement. break can be

Solution 1:

The break must be literally nested inside the label. It's perfectly possible to call func from outside a labelled context, so break wouldn't refer to anything. The same goes for break and continue in reference to loops, they must be literally within the loop statement.

Put another way, a function must be a self-contained executable snippet. You must be able to look at a function and be able to tell what it does. break in that function doesn't obviously belong to any loop or label, it's nonsensical there. That meaning can't just be available at call-time, it must be available at time of declaration.


Post a Comment for "Labeled Statement - Incorrect Definition?"