Dost it make sense to return undefined in else branch?
Today, I noticed a code snippet during code review, it looks like this:
1 | const getUserInfo(user: User) { |
The code is trying to get the user info, if the user is active, it will return the user info, otherwise, it will return undefined. But does it make sense to return undefined in the else branch? In JavaScript, if a function does not return anything, it implicitly returns undefined. So, the above code can be refactored to:
1 | const getUserInfo(user: User) { |
Similarly to the following code.
1 | const fetchData = async () => { |
Which can be simplified to:
1 | const fetchData = async () => { |