Docly Developers
Function Updated 17 Oct 2026

switch(value)

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

valueexpressionrequired

Value/expression to evaluate in the following case statements.

Returns

Nothing.

Example

Normal JavaScript, 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');
}