I used recursion without knowing what recursion was at the beginning of my programming journey, it just worked for me. But after understanding what recursion is and what it does, I was surprised and perplexed. It's a way of solving problems with elegance and beauty that leaves you amazed. Once you learn what and how to use recursion, your world changes completely AND EVEN OUTSIDE OF PROGRAMMING!. The concept of recursion may seem complex at first, but once you understand it, it's simply easy.
But enough talk, let's show you what it really is.
Recursion is a programming technique used in many algorithms. It's almost mandatory to know what it is and how it works if you want to become a good programmer.
Okay, here we go. Suppose you have a locked suitcase and you don't have the key. Now suppose you also have a set of boxes, one of which has a key. The boxes have more boxes inside them, how would you solve this?

Set up a pile of the boxes to be analyzed, take a box and look at what's inside, if you find another box inside it, put it in a new pile to look at later. If you find the key, that's it. Repeat.

Look inside the box, if you find another box, look inside the box again (new box). If you find the key, it's over.
The first approach uses loops (while, for), while the second uses recursion.
Recursion is basically when a function calls itself.
function fatorial(number) {
if(number == 1) return;
return number * fatorial(number - 1)
}To solve problems, you can use these two approaches, I'll tell you more about them in the next topic.
The two approaches literally do the same thing, but when you look at the second approach I think you'll find it more objective and clearer.
When you know that the first approach is faster than the second (recursion) you'll stay, right? 🤔
Loops can improve your program's performance. Recursion improves your developer's performance. Choose what is most important for your situation
In short, if you need a fast program you can opt for loops, but if it's not a problem, always opt for recursion. Recursion makes your code clearer, more objective and more ELEGANT
Recursion is much more complex than that, it was just a summary and it shouldn't be a “tutorial” but a post that is meant to leave you with even more doubts! Research, study recursion, it will improve your performance as a programmer. It will improve your algorithms on another level!
Font: Grokking Algorithms (An Illustrated Guide for Programmers and Other Curious People)