8000 Default value to arguments when destructuring · evozonjs/javascript@b4cbc92 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4cbc92

Browse files
author
Alex Pausan
committed
Default value to arguments when destructuring
1 parent 904ff74 commit b4cbc92

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,26 @@ Other Style Guides
775775
}
776776
```
777777
778+
<a name="functions--mutate-params"></a><a name="7.14"></a>
779+
- [7.14](#functions--default-value-destructuring) Always use a default value for an argument when destructuring it.
780+
781+
> Why? Destructuring an undefined/null argument will result in an error.
782+
783+
```javascript
784+
785+
// bad
786+
function getFullName({ firstName, lastName }) {
787+
return `${firstName} ${lastName}`;
788+
}
789+
790+
// good, defaults to an empty object
791+
function getFullName({ firstName, lastName } = {}) {
792+
return `${firstName} ${lastName}`;
793+
}
794+
```
795+
796+
797+
778798
**[⬆ back to top](#table-of-contents)**
779799
780800
## Arrow Functions

0 commit comments

Comments
 (0)
0