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. Adding the type here is unnecessary TypeScript will be able to infer the type of your variable from the type of the value it is given

let <name>: <type> = <value>;

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