A comment is text ignored by the Arcade compiler. Comments allow you to document expressions in-line using plain language. They can be critical to helping others understand complex expressions. They can also be used to provide attribution or links to outside documentation.
Arcade allows you to write single-line and multi-line comments.
Single-line comments must be preceded by two forward slashes (e.g. //
).
Use dark colors for code blocksCopy
1
// This is a single-line comment
Use dark colors for code blocksCopy
1
$feature.POPULATION / AreaGeodetic($feature, "square-miles"); // Calculates population density
Use dark colors for code blocksCopy
1
2
3
// You can stack single-line comments
// if you don't want to use a multi-line comment
$feature.POPULATION / AreaGeodetic($feature, "square-miles");
Multi-line comments may be enclosed within /* */
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
/*
* Calculates Simpson's Diversity Index.
* Example usage:
*
* var di = simpsonsDiversityIndex([404, 210, 0, 98]);
*/
function simpsonsDiversityIndex(values) {
// define function block here
}
The /* */
syntax may also be used to add multiple comments on a single line.
Use dark colors for code blocksCopy
1
Attachments($feature, 0 /*minsize*/, 1000000 /*maxsize*/, true /*inc metadata*/)
Comments may be used to disable statements while debugging expressions, or to test multiple scenarios.
Use dark colors for code blocksCopy
1
2
3
4
// I'm not sure which unit will be most appropriate
// $feature.POPULATION / AreaGeodetic($feature, "square-miles");
// $feature.POPULATION / AreaGeodetic($feature, "square-kilometers");
$feature.POPULATION / AreaGeodetic($feature, "square-meters");
In this workflow, comments are useful ways to document test values while writing an expression. Testing is quick when you disable/enable each set of test values line by line.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
function diversityIndex(values){
// calculation would go here. It is irrelevant for this example.
}
// var testValues = [0, 0, 0, 0]; // returns NaN --- fix this! Should be 0
// var testValues = [100, 0, 0, 0]; // returns 0
// var testValues = [100, 100, 100, 100]; // returns 75
// var testValues = [null, null, null]; // returns NaN --- Should be null
var testValues = [234, 775, 10, 1999]; // returns 49
diversityIndex(testValues);