Statements

An expression is a list of instructions that evaluate to a value. Each instruction in the expression is also known as a statement. Statements are preceded with a keyword or identifier indicating a function name or variable name. Statements typically end with a semi-colon.

Single-line expressions

Single-line expressions usually consist of one statement. Because there is only one statement, the use of an explicit return and semi-colon is not necessary.

Use dark colors for code blocksCopy
1
"Hello world"  // returns "Hello world"

Multiple statements on one line

You may write multiple statements on a single line. In this scenario, each statement must be separated with a semi-colon. This pattern is more common with variable declarations.

Use dark colors for code blocksCopy
1
2
3
var x = 3; var y = 4;
return x + y;
// returns 7

We suggest you avoid returning values on lines that contain multiple statements. While the following example is legal syntax, it is hard to read.

Use dark colors for code blocksCopy
1
2
var x = 3; var y = 4; return x+y;
// returns 7

Multi-line expressions

Multi-line expressions consist of multiple statements, including variable declarations, function definitions, and invoking functions. Because multi-line expressions can be complex, we suggest you use semi-colons to mark the end of statements and explicit returns to indicate the end of a script.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
function calculateRatio(values, index){
  var value = values[index];
  return value / Sum(values);
}

var values = [ $feature.CategoryA,  $feature.CategoryB,  $feature.CategoryC, ];
var selectedIndex = 1;
var ratio = calculateRatio(values, selectedIndex);
return ratio;

One statement on multiple lines

Some statements can become very long because of long variable names, multiple chained functions, functions with a long list of parameters, and long conditional statements. In these scenarios, you should break up the statement across multiple lines to make it easier to read.

Chained functions

Because Arcade allows you to chain functions, a single statement can become quite long.

Use dark colors for code blocksCopy
1
2
// multiple functions in one statement chained on one line
AreaGeodetic(Intersects(Filter(FeatureSetByName($map, "public lands", ["class"], true), "class = 'sensitive'"), $feature), "square-kilometers");

Break up the statement across multiple lines to make it easier to read.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
// multiple functions in one statement chained on multiple lines
AreaGeodetic(
  Intersects(
    Filter(
      FeatureSetByName($map, "public lands", ["class"], true),
      "class = 'sensitive'"
    ),
    $feature
  ),
  "square-kilometers"
);

In the case of FeatureSet functions, it helps to assign the FeatureSet to a variable.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
var publicLands = FeatureSetByName($map, "public lands", ["class"], true);
AreaGeodetic(
  Intersects(
    Filter( publicLands, "class = 'sensitive'"),
    $feature
  ),
  "square-kilometers"
);

Long conditional statements

Some conditional statements can be complex.

Use dark colors for code blocksCopy
1
2
3
if((score == "High" || value > 90) && (cases > 0 && status == "active")){
  // statements execute in this block if the condition is true
}

Break the conditional statement onto multiple lines to help readability.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
if(
  (score == "High" || value > 90) &&
  (cases > 0) &&
  (status == "active")
){
  // statements execute in this block if the condition is true
}

See if - else and bitwise operators for more information about conditional statements.

Guidelines

  • Keep one statement per line. It makes the script easier to read.
  • Long statements should be broken up across multiple lines. Line breaks should occur in the following locations:
    • In a set of chained functions, at the start of invoking a function.
    • In functions with a long list of parameters, or a long value, at the start of a parameter.
    • Long conditional statements should be broken up after an operator is used.

Keywords

A keyword is a reserved word in the Arcade language. These words indicate an instruction to execute in the Arcade engine.

The following are keywords in Arcade.

KeywordInstruction
breakBreaks or stops the execution of statements in a for loop. See break for more information.
continueContinues the execution of statements in a for loop. See continue for more information.
elseIndicates the start of a block of statements to execute when a condition defined by a preceding if evaluates to false. See else for more information.
forIndicates the start of a block of statements to execute iteratively based on an iterator or conditional statement. See for for more information.
functionDefines a function. See functions for more information.
ifIndicates the start of a block of statements to execute when a condition defined in parentheses evaluates to true. See if for more information.
inPreceded by for and a variable declaration. This instructs the statement to iterate through all items in a FeatureSet or Array, or properties in a Dictionary or Feature. See for...in for more information.
returnIndicates the value to return from a function or a script. See return for more information.
varDeclares a variable. See variables for more information.
whileIndicates the start of a block of statements to execute iteratively based on a conditional statement. See while for more information.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.