switch(value) Last updated: 17. Oct 2026
Runs the code after the case that matches a value — a more readable alternative to a series of if/else statements.
HashJS rules:
- Each case must be a single literal value, such as 'apple' or 3. Expressions and variables are not allowed after case.
- Values are compared with .NET equality, without type conversion: case "1" does not match the number 1.
- default matches as soon as it is reached, so place it last.
- A case without break falls through to the code of the next case.
Parameters
| Name | Type | Description |
|---|---|---|
| value | expression | Value/expression to evaluate in the following case statements. |
Returns
Nothing.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.let value = 'banana';
switch (value) {
case 'apple':
write('This is an apple');
break;
case 'banana':
write('This is a banana');
break;
default:
write('Unknown fruit');
} Output
The JS code above produces the output shown below:This is a banana