Created
October 28, 2018 01:58
-
-
Save tkssharma/f2299ef11e52681553e2618d6f7d9b1a to your computer and use it in GitHub Desktop.
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 arr: number[] = [1, 2, 3]; | |
| arr.push(4); | |
| const myObj: { x: number } = { x: 1 }; | |
| myObj.x = 2; | |
| let n2: string | undefined = Math.random() > 0.5 ? undefined : "test"; | |
| // console.log(n2.substring(0, 1)); // Won't compile since can be null | |
| if (n2 !== null) { | |
| console.log(n2.substring(0, 1)); | |
| } | |
| function f1(optional?: string): void { | |
| if (optional === undefined) { | |
| // Optional parameter was not provided OR was set to undefined | |
| } else { | |
| // The optional parameter is for sure a string (not undefined) | |
| } | |
| } | |
| let primitiveWithUndefined: number | undefined = undefined; | |
| function functOptionalArg(primitiveOptional?: number): void { | |
| // ... | |
| } | |
| functOptionalArg(); | |
| functOptionalArg(undefined); | |
| functOptionalArg(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment