r/JavaScriptTips • • Oct 31 '22

the first or the secound function ?

Post image
10 Upvotes

8 comments sorted by

4

u/[deleted] Oct 31 '22

Assuming findbyId has its own catch.

1st looks better. You are using async await. Code is clean and single indentation.

In the 2nd I guess you need to wait anyway for save before proceeding. You may have to use another then or await.

2

u/KeRou09 Oct 31 '22

💯💯

2

u/[deleted] Oct 31 '22

Dude, what indent color extension is that?

2

u/KeRou09 Oct 31 '22

Tokyo night

2

u/bualing Nov 03 '22 edited Nov 03 '22

First will fail on runtime if employee be falsey

1

u/TheShuttleCrabster Oct 31 '22

I'm Kinda hating on .then chains nowadays.

Edit: do use a try catch in first one if you prefer it.

0

u/MrPoopypantalons Oct 31 '22

You can also write the first function in a Try..catch block to make it look more like a second option.

-3

u/GaymerWasTaken Oct 31 '22

The second just feels cleaner and even has error handling so if it's written right is a 10/10 for me