Operator

Operator

Operator

Function

BT supports common operators such as arithmetic, comparison, logic, bit operations, assignment, conditions and member access. It is recommended to use parentheses to clarify the order in complex expressions.

Arithmetic operator

OperatorDescription
+Addition or string concatenation.
-Subtraction.
*Multiplication.
/Division.
%Take remainder.
**Power operation.

Comparison operator

OperatorDescription
>Greater than.
<Less than.
>=Greater than or equal to.
<=Less than or equal to.
==Loose equal.
!=Loose does not equal.
===Strictly equal, return true only when the value and type are consistent.
!==Strictly not equal.

Logical operator

OperatorDescription
&&Execute and return the right side only if the left side is true, otherwise return the left side directly.
||If the left side is true, return directly to the left side, otherwise execute and return to the right side.
!Negate according to BT truth rules.
??Only execute and return to the right side if the left side is null or empty, otherwise return to the left side directly.

Bit operator

OperatorDescription
&Bitwise AND, compare the binary representations of two numbers bit by bit. If the two corresponding bits are both 1, the result of the bit is 1, otherwise it is 0
|Bitwise OR, compare the binary representations of two numbers bit by bit. If at least one of the two corresponding bits is 1, the result of that bit is 1, otherwise it is 0
^Bitwise XOR, compare the binary representation of two numbers bit by bit. If the two corresponding bits are different, the result of the bit is 1, otherwise it is 0
~Bitwise inversion, invert the binary representation of a number bit by bit, that is, 0 becomes 1, and 1 becomes 0
<<Shift left, shift all binary bits of a number to the left by a certain number of bits, and fill the empty bits in the sign bit (the leftmost bit) with 0
>>Shift right, shift all binary digits of a number to the right by a certain number of bits, add 0 to the left for positive numbers, 1 for negative numbers to the left, and discard the right side

Assignment operator

OperatorDescription
=Assignment, returns the value of the expression on the right.
+=Calculates and writes back as binary +, supports numerical addition and string concatenation.
-=Compute as binary - and write back.
*=Compute as binary * and write back.
/=Calculates and writes back the binary /, the result is a floating point number.
%=Compute as binary % and write back.
<<=Calculated as binary << and written back.
>>=Compute as binary >> and write back.
&=Compute as binary & and write back.
^=Compute as binary ^ and write back.
|=Calculated as binary | and written back.

Syntax

Parameters

ParametersTypeIs it requiredDefault valueValid range or optional valueMeaning
targetVariable/Array/ObjectYesNoneVariable variables, array numeric subscripts, ordinary object fields, class instance fieldsA writable target that receives write-back results.
valueAnyYesNoneDetermined by the corresponding binary operatorThe rvalue of an ordinary assignment, or the right operand of a compound assignment.

Property chains and dynamic subscripts can be targeted, such as config.title, items[index], config.article.id. Object expressions and subscript expressions in the target are evaluated only once; the execution order is fixed as "resolve target reference → read current value (compound assignment) → evaluate rvalue → operation → write back to the same target".

Return Value

  • Normal = returns the value of the expression on the right.
  • Compound assignment returns the new value after writing back.
  • Variables, local variables, parameters and closure capture variables inherit their respective scopes; compound assignment cannot modify constants.

Increase and decrease

Function and syntax

operatorreturn valuewrite back result
target++Old value before modificationCurrent value plus 1.
target--Old value before modificationCurrent value minus 1.
++targetNew modified valueCurrent value plus 1.
--targetModified new valueCurrent value minus 1.

target must be a writable variable, array numeric subscript, ordinary object field or class instance field, and the current value can only be Int or Float. Strings, Boolean values, null, empty, and other objects cannot increment or decrement.

Conditional operator

? : Returns one of two expressions based on a condition. When the right side of : is omitted, empty is returned if the condition is not met.

Members and calls

OperatorDescription
()Change the order of operations or call a function.
[]Access array subscripts, string characters, or object dynamic fields.
.Access object fields or prototype methods.

Notes

  • &&, || and ?? are all short-circuit evaluations. When the result can be determined on the left side, the function call, field access or other expression on the right side will not be executed.
  • ?? only handles null and empty, and will not treat 0, false, and empty strings as missing values.
- || uses BT truth rules, null, empty, 0, false, empty strings, empty arrays, and empty objects are considered false.
  • Ordinary assignment, compound assignment and auto-increment and auto-decrement will fix the object expression and dynamic subscript to the same target reference, and will not call the function in the target repeatedly due to writeback.
- Properties of string and Bytes subscripts, BT / Math static objects, extension objects, and class definition objects are read-only; assignment to these targets throws an error.
  • Non-lvalues such as 1 += 2, foo()++, and (a + b) += 1 will report errors at compile time, and constants cannot use compound assignment or auto-increment and self-decrement.
- There are currently no **=, &&=, ||=, ??= operators; they should be explicitly written using existing ordinary assignment and short-circuiting expressions when needed.