Skip to main content
A script body is a sequence of statements that run from top to bottom. These are the available statements: An expression statement evaluates an expression and discards the result. It’s mainly useful for calling a resource function for its side effect. There are no loops and no user-defined functions.

if statements

An if statement runs its body only when its condition is true. The condition must be in parentheses and the body in curly braces.
Add else if branches to test more conditions in order, and an else branch to run when no condition matched:
  • The condition must evaluate to a boolean. if (1) or if (name) is an error: write if (name != null) instead.
  • Curly braces are always required, even for a single statement.
  • Each body is its own scope.

return

return ends the script immediately. Its value becomes the returnValue of the response, and any statements after it are skipped.
A script returns null if it uses a bare return or reaches the end of its body without a return.
The returned value must start on the same line as return. A value on the next line isn’t part of the return, so the script returns null.