Now this is a horrible code to read because for every if you need to look for corresponding else and you need to constantly jump between lines when trying to understand the code.
Why early return is so good is because with it, every time an error occurs that should end the function in earlier step, you can return from the function and not think about that branch of execution after.
I feel like you did not provide complex enough example to show of what a huge difference in code readability can early return make.
Let's say we have some complicated fetch that needs to first get some ticket and then use it in a 2nd request.
Now this is a horrible code to read because for every
if
you need to look for correspondingelse
and you need to constantly jump between lines when trying to understand the code.Why early return is so good is because with it, every time an error occurs that should end the function in earlier step, you can return from the function and not think about that branch of execution after.
And this is the main reason for early return.