Operators and concatenating strings

An operator is a symbol that tells the interpreter to perform specific mathematical or logical manipulations. HaasScript is rich in built-in operators and provides the following type of operators:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Misc Operators

This section will explain the arithmetic and relational operators along with how to concatenate strings.

Arithmetic Operators

Following table shows all the arithmetic operators supported by HaasScript language. Assume variable A holds 9 and variable B holds 5 then:

OperatorDescriptionExample
+AddA + B = 14
SubtractA – B = 4
*MultiplyA * B = 45
/DivideA / B = 1.8
%ModulusB % A = 4
^ExponentA^2 = 81
Unary negation-A = -9

Relational Operators

Following table shows all the relational operators supported by HaasScript language. Assume variable A holds 10 and variable B holds 20 then

OperatorDescriptionExample
==Checks if the values are equal or not, if yes then condition becomes true.(A == B) is false
~= or !=Checks if the values are equal or not, if not then condition becomes true.(A != B) is true
>Checks if the value on left is greater than the value on right, if yes then condition becomes true.(A > B) is false
<Checks if the value on left is less than the value on right, if yes then condition becomes true.(A < B) is true
>=Checks if the value on left is greater than or equal to the value on right, if yes then condition becomes true.(A >= B) is false
<=Checks if the value on left is less than or equal to the value on right, if yes then condition becomes true.(A <= B) is true

Logical Operators

Following table shows all the logical operators supported by HaasScript language. Assume variable A holds true and variable B holds false then

OperatorDescriptionExample
andCalled the logical AND operator. If both operands are non-zero (or non-nil) then condition becomes true. (A and B) is false
orCalled the logical OR operator. If either of the two operands are non-zero (or non-nil) then the condition becomes true.(A or B) is true
notCalled the logical NOT operator. Used to reverse the logical state of its operand. If a condition is true then logical NOT operator will make it false. (not A) is false

Misc Operators

Miscellaneous operators supported by HaasScript include concatenation and length.

OperatorDescriptionExample
..Concatenates two strings.a..b where a is “Hello ” and b is “World”, will return “Hello World”.
#An unary operator that returns the length of a string or table.#”Hello” will return 5
Back to: HaasScript Fundamentals > Operators