Expressions can be used as input arguments in blocks. For example, use the Expression true block to check if an expression evaluate to true.
To write an expression, switch to “expression mode” by tapping the strike through “fx” icon within an input argument field, tap it again to return to “constant mode”.
An expression is any valid unit of code that resolves to a value. Automate has the following expression categories:
3.14 + 15. See arithmetic operators."Good" ++ "bye". See special operators.Automate has the following types of operators:
Arithmetic operators take numerical values as their operands and returns a single numerical value. Any non-numerical operand is first converted (coerced) to a number. If all operands are of the bigint type then the result is as well. Mixing bigint and number operands will fail, use the to number operator or bigint function to explicitly use either.
A binary operator;
1 + 2 returns 3.
A binary operator;
2 - 1 returns 1.
A binary operator;
2 * 2 returns 4.
A binary operator;
10 / 3 returns 3.333.
10 / 0 returns Infinity.
10n / 3n returns 3n (bigint).
10n / 0n fails.
A binary operator;
10 // 3 returns 3.
10 // 0 returns Infinity.
10n // 0n fails.
A binary operator that returns the remainder of dividing the two operands;
12 % 5 returns 2.
12 % 0 returns NaN.
12n % 0n fails.
A unary prefix operator that returns the negation of its operand;
-(-5) returns 5.
Bitwise operators take numerical values as their operands and returns a single numerical value. Any non-numerical operand is first converted (coerced) to a number. A number operand is treated as a set of 32 bits. If all operands are of the bigint type then the result is as well. Mixing bigint and number operands will fail, use the to number operator or bigint function to explicitly use either.
A binary operator that returns a one in each bit position for which the corresponding bits of both operands are ones;
0b0101 & 0b0011 returns 0b0001.
A binary operator that returns a one in each bit position for which the corresponding bits of either or both operands are ones;
0b0101 | 0b0011 returns 0b0111.
A binary operator that returns a one in each bit position for which the corresponding bits of either but not both operands are ones;
0b0101 ^ 0b0011 returns 0b0110.
A unary operator that inverts the bits of its operand;
~0b1 returns 0xFFFFFFFE.
~0b1n returns -1n (bigint).
A binary operator that shifts the bits to the left;
0b10010111 << 1 returns 0b00101110.
A binary operator that shifts the bits to the right, keeping the sign of a negative number;
0b10010111 >> 1 returns 0b11001011.
A binary operator that shifts the bits to the right, without keeping the sign of a negative number;
0b10010111 >>> 1 returns 0b01001011.
Fails with bigint.
A comparison operator compares its two operands and returns a logical value based on whether the comparison is true or false.
The operands can be numeric or text.
Numeric comparison of number and bigint (mixing) operand types is allowed, unlike arithmetic operators,
but not of other value types, i.e. comparing number with text always returns 0.
null compares as less to a non-null value.
The return type is always number, either 1 for true or 0 for false.
Texts are compared on case-sensitive lexicographical order.
A binary operator that returns 1 if the operands are equal;
3 = 3 returns 1.
A binary operator that returns 1 if the operands are not equal;
3 != 3 returns 0.
A binary operator that returns 1 if the left operand is greater than the right operand;
2 > 2 returns 0.
A binary operator that returns 1 if the left operand is greater than or equal to the right operand;
2 >= 2 returns 1.
A binary operator that returns 1 if the left operand is less than the right operand;
2 < 2 returns 0.
A binary operator that returns 1 if the left operand is less than or equal to the right operand;
2 <= 2 returns 1.
Automate does not have a value type nor literals for true or false, instead the following are considered false:
All other values are considered true.
A binary operator that returns left operand if it evaluate to false, otherwise right operand is returned;
2 && 3 returns 3.
A binary operator that returns left operand if it evaluate to true, otherwise right operand is returned;
2 || 3 returns 2.
null || 0 || "Hi" returns "Hi".
A unary prefix operator that returns 1 if the operand evaluate to false, otherwise 0 is returned;
!3 returns 0.
An unary prefix operator that returns the operand converted to a number;
+2n returns 2.
+"2" returns 2.
+"0xFF" returns 255.
An unary prefix operator that returns the operand converted to text;
++2 returns "2".
A binary operator that returns the two operands concatenated into a text;
"Good"++"bye" returns "Goodbye", 2++2 returns "22".
A ternary operator, operand ? operand : operand; If the first operand evaluate to true the seconds operand is returned,
otherwise the third operand is returned;
2=2 ? "two" : "other" returns "two".
An unary prefix operator;
#"Hi" returns 2.#[1,2] returns 2.#{"a":1,"b":2} returns 2.A binary operator, operand[operand];
"Hi"[1] returns 105.["a","b","c"][1] returns "b".{"a":1,"b":2}["b"] returns 2.A constant expression can only include null, and literals for number, bigint, text, array and dictionary.