Language Syntax
Tezz syntax is designed to be highly readable, borrowing the best parts of modern JavaScript, Swift, and Rust.
Variables
Declare mutable variables with let and immutable variables with const.
let age = 21
const name = "Abhinav"
// Reassignment
age = 22
Functions
Functions are declared using the fn keyword. For asynchronous operations, prefix the function with async.
fn calculateTotal(price, tax) {
return price + (price * tax)
}
async fn fetchUserData(id) {
let response = await fetch("https://api.example.com/users/" + id)
return await response.json()
}
Control Flow
Standard branching and looping constructs are fully supported.
// If / Else
if age >= 18 {
print("Adult")
} else {
print("Minor")
}
// While Loop
let count = 0
while count < 5 {
print(count)
count += 1
}
// For Loop
let numbers = [1, 2, 3]
for n in numbers {
print(n)
}
Error Handling
Use try and catch to gracefully handle exceptions.
try {
let data = parseJSON(invalidString)
} catch err {
print("Failed to parse data!")
}