Intro

Javascript is a dynamically type language. The types of variables are evaluated at runtime based on the contents of the variable.

Typescript is a superset of Javascript which adds static typing to the language (amongst other things).

There are two kinds of types in Javascript; Primative and Reference.

  • Primative - Stored on the stack in the memory location assigned to the variable.
  • Reference - Stored on the heap as a pointer to a location in memory.

Primative Types

String

Strings can be defined with either 'single' or "double" quotes.

javascript
// Define a String
const name = "Jim Bob";

Number

There is a single number type in Javascript to represent all numbers (int, float, etc..)

javascript
// Define a Number
const age = 42;

Boolean

Booleans are true or false values.

javascript
// Define a Boolean
const smoker = false;

Null

A null value represents the intentional absence of any object value. null is a falsey value.

javascript
// Define a Null
const shoes = null;

Undefined

A variable is undefined when it is declared with no defined value.

javascript
// Define a variable with an undefined value
let pants;

Symbol

Symbols were added to Javascript in ES6. Symbols represent values that are guaranteed to be unique.

javascript
// Define a symbol
const shirt = Symbol();

Reference Types

Array

An array is an indexed list of values.

javascript
// Define an Array
const stuffAndThings = ["stuff", "things"];

Object Literal

An object is a hash of key/value pairs.

javascript
// Define an Object
const stuffAndThings = {
  stuff: "stuff",
  things: "things"
};