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
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
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 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
// 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
// Default function parameters | |
const tweetLength = (message = 'A default tweet') => { | |
return message.length; | |
} |
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
function add(a: number, b: number) { | |
return a + b; | |
} | |
const result = add(2, 4); | |
result.toFixed(2); // ✅ | |
result.length; // ❌ - length is not a property of number types |
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 list = [10, 22, 4, null, 5]; | |
list.push(6); // ✅ | |
list.push(null); // ✅ | |
list.push('nope'); // ❌ - type 'string' is neither of type 'number' or '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
let aBoolean: boolean = true; | |
let aNumber: number = 10; | |
let aString: string = 'woohoo'; |
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
// First method is using the square bracket notation | |
let messageArray: string[] = ['hello', 'my name is fred', 'bye']; | |
// Second method uses the Array keyword notation | |
let messageArray: Array<string> = ['hello', 'my name is fred', 'bye']; |