Operators Reference
Djazair provides standard arithmetic, comparison, logical, bitwise, assignment, increment/decrement, and identity operators.
Arithmetic Operators
Basic mathematical calculations:
let sum = 10 + 5 # Addition => 15
let diff = 10 - 5 # Subtraction => 5
let prod = 10 * 5 # Multiplication => 50
let div = 10 / 4 # Division => 2.5
let fdiv = 10 // 4 # Floor division => 2
let power = 2 ** 3 # Exponentiation => 8
let rem = 10 % 3 # Modulo => 1
Increment & Decrement
Both prefix and postfix forms are supported:
let n = 5
print(n++) # Postfix: prints 5, then increments to 6
print(++n) # Prefix: increments to 7, prints 7
print(n--) # Postfix: prints 7, then decrements to 6
print(--n) # Prefix: decrements to 5, prints 5
Logical Operators
Logical chaining uses descriptive keywords: and, or, and not:
let condition1 = True
let condition2 = False
print(condition1 and condition2) # => False
print(condition1 or condition2) # => True
print(not condition1) # => False
Identity Operators (is / is not)
Check if two variables reference the same object in memory:
let a = [1, 2]
let b = a
let c = [1, 2]
print(a is b) # => True (same reference)
print(a is c) # => False (different objects)
print(a is not c) # => True
print(Null is Null) # => True
Type Checking (instanceof)
Check if a value is an instance of a given type (pass type name as a string):
print(42 instanceof "Number") # => True
print("hi" instanceof "String") # => True
print(True instanceof "Bool") # => True
print(Null instanceof "Null") # => True
print([1,2] instanceof "Array") # => True
print({"a":1} instanceof "Map") # => True
class Animal end
class Dog is Animal end
let d = Dog()
print(d instanceof Dog) # => True
print(d instanceof Animal) # => True (inheritance)
Membership Operators (in / not in)
Check if items exist in strings, arrays, or maps:
print(2 in [1, 2, 3]) # => True
print(5 not in [1, 2, 3]) # => True
print("name" in {"name": "A"}) # => True (key exists)
print("orld" in "Hello World") # => True (substring)
Bitwise Operators
Perform operations at the bit level for integers:
print(5 & 3) # Bitwise AND => 1
print(5 | 3) # Bitwise OR => 7
print(5 ^ 3) # Bitwise XOR => 6
print(~5) # Bitwise NOT => -6
print(8 << 2) # Left Shift => 32
print(8 >> 2) # Right Shift => 2
Bitwise Assignment Operators
Djazair also supports assigning bitwise values directly:
let y = 5
y &= 3 # y becomes 1
y |= 3 # y becomes 3
y ^= 3 # y becomes 0
y <<= 2 # y becomes 0
y >>= 2 # y becomes 0