Created
February 27, 2022 11:15
-
-
Save GermaVinsmoke/13acdbd00b03d01127a0bdb8d52fb74d to your computer and use it in GitHub Desktop.
File having code on how to create named parameters in Javascript/Typescript
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
| /** | |
| * Parameters needs to be passed in order π£ππ« | |
| * Sometimes, by mistake can pass in wrong order π€ | |
| */ | |
| const fun1 = ( | |
| one: string, | |
| two: number, | |
| three: boolean, | |
| four: string, | |
| five: number | |
| ) => { | |
| console.log('Function without named parameters'); | |
| }; | |
| interface FunctionParameters { | |
| one: string; | |
| two: number; | |
| three: boolean; | |
| four: string; | |
| five: number; | |
| } | |
| /** | |
| * Can pass parameters in any order we want π | |
| * No need to remember the order π | |
| */ | |
| const fun2 = ({ one, two, three, four, five }: FunctionParameters) => { | |
| console.log('Function with named parameters'); | |
| }; | |
| fun1('test', 1, true, 'four', 5); | |
| fun2({ | |
| five: 4, | |
| three: false, | |
| two: 1, | |
| one: 'one', | |
| four: 'test', | |
| }); | |
| export { fun1, fun2 }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment