Skip to content

Instantly share code, notes, and snippets.

@xdesro
Created May 20, 2021 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdesro/ba7dc238943defa59e1def18490710e4 to your computer and use it in GitHub Desktop.
Save xdesro/ba7dc238943defa59e1def18490710e4 to your computer and use it in GitHub Desktop.
Using optional chaining operators instead of logical and operators.
// 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