Created
May 20, 2021 16:25
-
-
Save xdesro/ba7dc238943defa59e1def18490710e4 to your computer and use it in GitHub Desktop.
Using optional chaining operators instead of logical and operators.
This file contains 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
// Before | |
const postsByAuthor = (posts) => { | |
return this.posts.filter( | |
(post) => post.author && post.author.fields.name == this.teamMember.name | |
); | |
}, | |
// After | |
const postsByAuthor = (posts) => { | |
return this.posts.filter( | |
(post) => post.author?.fields.name == this.teamMember.name | |
); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment