Comp 110 TypeScript Syntax

TypeScript Language Constructs

Comment out content.

//This is a comment!
/* This is also a comment! */

Primitive types.

boolean, number, string

Declare a variable.

let <name>: <type>;

Initialize a variable.

<name> = <value>;

Declare and initialize a variable together.

let <name>: <type>;

Declare an array. (Type is implied by the contents of the array. If multiple types are provided, array will be of type 'any.')

let <name>: <type>[] = [];
//This is currently initialized to be an empty array

Test Equality

<value> === <value>

Declare a function.

let <function name> = (<parameters>): <return type> => {
}

A while loop.

// declare and initialize counter
while (<boolean expression>) {
    // do something
    // increment counter or set boolean expression to false
}

A for loop.

for (<declare and initialize counter>; <boolean expression>; <increment counter> {
// do something
}