Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!

Variables & Methods

Variables 

A variable is like a box that contains information (data). Each variable has a label, and you can put different data in it any time.

Variables are declared (created) with the let keyword. A variable must be declared before it is used.

Data values are assigned to variables with =.

let location = 'Paris';
let numArtists = 9000;
let isBeautiful = true;

// ✔ OK
// This was declared above, so it can be changed.
location = 'Prague';

// ✖ ERROR
// 'isExpensive' was never declared with 'let'.
isExpensive = false;

Case Matching

Variable and function names are case-sensitive. They must match exactly.

let numApples = 10;

// ✖ ERROR
// 'A' should be uppercase.
numapples = 11;

// ✖ ERROR
// 'print' should be lowercase.
Print('Hello!');

Basic Data Types 

There are 3 basic types of data:

// Numbers
42     // positive
-62    // negative
1.618  // fraction (aka 'floating point' or 'float')

// String (surrounded with single-quotes)
'This is a string!'

// Booleans
true
false

Initializing Variables 

New variables must always be given a value.

If you’re not sure what to use, pick the “empty” version of the type you need:

let myString = '';
let myNumber = 0;
let myBoolean = false;

Null 

Unlike many other languages, THT does not have a null, nil, or undefined value. (See “The Billion Dollar Mistake”).

If you need a way to represent “nothing”, consider using a Result object, or an empty value for the given type.

Variable Names 

Variables and function names are always written in camelCase format:

Examples:

user
userId
firstName
isDeleted
numRecords
httpVersion
userHasIphone
convertJsonToXml

Naming Tips

Coming up with good names is one of the most important (and difficult) skills in programming.

Always take the extra time to find names that clearly represent what they are labelling.

Common Guidelines:

Examples:

✖ Bad         ✔ Better
------        ------------
usr           user
fname         firstName
nbrPosts      numPosts
cmntTxt       commentText
banned        isBanned
activeTime    numDaysActive
distance      distanceKm
userList      users
active        activeUsers, isActive
a             (be more specific)
temp          (be more specific)

Methods 

Methods are functions that are attached to data. They are called using the dot . operator.

All built-in data types have methods.

let text = '  Tipsy Turtle  ';

text.trim();
//= 'Tipsy Turtle' (no extra spaces)

text.contains('Turtle');
//= true

text.length();
//= 14  (including spaces)

Modules

A module is a bundle of related functions. Module names are always UpperCamelCase.

THT comes with essential modules like Math, Date, and Web.

Math.floor(3.15);
//= 3 (rounded down)

Math.pi();
//= 3.1415926535898

Date.now();
//= current timestamp in seconds

File.read('words.txt');
//= (contents of 'words.txt' file)

ReferenceAll built-in modules and methods are listed in the Manual.