by Ricardo “Rudxain” Fernández Serrata
Version 1 (September 26, 2023)
Download (91 downloads)
By using logical operators, you can add comments to expressions. No extra blocks required.
The parentheses I used are unnecessary in these specific cases, but parentheses are recommended to avoid surprises related to operator precedence.
To make sure that the interpreter optimizes code, so that the comments don't affect performance, use the ternary op in this way:
truthy constant ? expression : "comment"
Or this way:
falsy constant ? "comment" : expression
If your comment is not a falsy value, you can also use "&&":
"truthy-value comment" && expression
"||" requires evaluation of the left side expression, which can negatively affect performance when the left side is a variable, because variables can have any value, the interpreter can't optimize comments that use this operator. The variable on the left must be truthy, otherwise the comment is returned.
If you don't know what "truthy" or "falsy" means in AM, read the documentation: llamalab.com/automate/doc/expression.html#logical_operators
Or maybe even the MDN documentation about Javascript truthiness:
developer.mozilla.org/en-US/docs/Glossary/Falsy
developer.mozilla.org/en-US/docs/Glossary/Truthy
[] and {} are falsy. [null] and {"": null} are truthy because they aren't empty (even if the only value that fills them is null)
Rudxain profile: llamalab.com/automate/community/flows/42921
LICENSE: https://unlicense.org
5 stars | 1 | |
4 stars | 2 | |
3 stars | 0 | |
2 stars | 0 | |
1 star | 0 | |
Reports | 0 |
Rate and review within the app in the Community section.