I’m building a JavaScript parser and there seem to be some differing opinions.
ECMA-262 seems to suggest that it is not optional, but Wikipedia says it is.
SwitchStatement :
switch (Expression)CaseBlockCaseBlock :
{CaseClausesopt}
{CaseClausesopt DefaultClause CaseClausesopt}
case default:is optional.
Does Wikipedia just mean that you can literally write case default: if you want?
EDIT
Just realised I was reading ECMA wrong. The first case block option i.e. { CaseClausesopt } allows you to miss out the default block. Case closed (if you’ll pardon the pun).
A CaseBlock can be either of the following:
That’s sort of a clumsy way of saying that there can be at most one DefaultClause, and you can put it anywhere in the CaseBlock.