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
Single-line comments must be preceded by two forward slashes (e.g. //
).
// This is a single-line comment
$feature.POPULATION / AreaGeodetic($feature, "square-miles"); // Calculates population density
// 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
Multi-line comments may be enclosed within /* */
/*
* 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.
Attachments($feature, 0 /*minsize*/, 1000000 /*maxsize*/, true /*inc metadata*/)
Comments for disabling statements
Comments may be used to disable statements while debugging expressions, or to test multiple scenarios.
// 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.
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);