This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variable initialization | |
let x = 10; // x is given the number type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let anUndefinedVariable: undefined = undefined; | |
let aNullVariable: null = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const darkestPlaceOnEarth = (): void => { | |
console.log('Marianas Trench'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Sizes { | |
Small = 1, | |
Medium, | |
Large, | |
} | |
Sizes.Small; // => 1 | |
Sizes.Medium; // => 2 | |
Sizes.Large; // => 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Sizes { | |
Small, | |
Medium, | |
Large, | |
} | |
Sizes.Small; // => 0 | |
Sizes.Medium; // => 1 | |
Sizes.Large; // => 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myFavoriteTuple: [string, number, boolean]; | |
myFavoriteTuple = ['chair', 20, true]; // ✅ | |
myFavoriteTuple = [5, 20, true]; // ❌ - The first element should be a string, not a number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myPetFamily: Array<string> = ['rocket', 'fluffly', 'harry']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myPetFamily: string[] = ['rocket', 'fluffly', 'harry']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let decimalNumber: number = 42; | |
let binaryNumber: number = 0b101010; // => 42 | |
let octalNumber: number = 0o52; // => 42 | |
let hexadecimalNumber: number = 0x2a; // => 42 |