Skip to content

Instantly share code, notes, and snippets.

View robertcoopercode's full-sized avatar

Robert Cooper robertcoopercode

View GitHub Profile
// Variable initialization
let x = 10; // x is given the number type
let anUndefinedVariable: undefined = undefined;
let aNullVariable: null = null;
const darkestPlaceOnEarth = (): void => {
console.log('Marianas Trench');
};
let whoKnows: any = 4; // assigned a number
whoKnows = 'a beautiful string'; // can be reassigned to a string
whoKnows = false; // can be reassigned to a boolean
enum Sizes {
Small = 1,
Medium,
Large,
}
Sizes.Small; // => 1
Sizes.Medium; // => 2
Sizes.Large; // => 3
enum Sizes {
Small,
Medium,
Large,
}
Sizes.Small; // => 0
Sizes.Medium; // => 1
Sizes.Large; // => 2
let myFavoriteTuple: [string, number, boolean];
myFavoriteTuple = ['chair', 20, true]; // ✅
myFavoriteTuple = [5, 20, true]; // ❌ - The first element should be a string, not a number
let myPetFamily: Array<string> = ['rocket', 'fluffly', 'harry'];
let myPetFamily: string[] = ['rocket', 'fluffly', 'harry'];
let decimalNumber: number = 42;
let binaryNumber: number = 0b101010; // => 42
let octalNumber: number = 0o52; // => 42
let hexadecimalNumber: number = 0x2a; // => 42