DEV Community

Fernando B 🚀
Fernando B 🚀

Posted on

6 1

Recursion is Recursion is Recursion...

I took on the challenge of completing freecodecamp curriculum just to see the extent of my self-taught learning over the years, and is going well so far. Never did it occurred to me that I rarely use recursion functions, because well is easier to do a forloop. I tried to learn recursion before and the problem was that most people teaching start with the factorial example or some other complicated example. Mixing a math principle with a new programming principle isn't the best choice and sometimes is better to start with an easier example.

Credit: Freecodecamp Basic Javascript

What is recursion?

Recursion is when a function calls itself over and over until it hits the base case(s). A recursive function needs an exit statement, otherwise known as the base case because is the last time the recursive function gets called before returning the result. Another thing to be aware is that variables need to be passed down on each recursion, unlike in loops where you can keep track with local variables.

A recursive function works well with things that are normally done in a loop where there is a computation that is stepping up or down.

A few other examples of recursive functions are:

Thanks for reading, and I hope you learned something today!

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (4)

Collapse
 
jonrandy profile image
Jon Randy 🎖️

You could always Google it 😀
Google recursion

Collapse
 
gcgbarbosa profile image
George C. G. Barbosa

haha, that is a very nice easter egg

Collapse
 
pomfrit123 profile image
***

If you use return in you if condition you don't need an else, just a little tip :)

Collapse
 
thefern profile image
Fernando B 🚀

Thanks for the tip, I prefer if/else for beginner examples it shows the branching off a bit clearer for beginners.

Image of PulumiUP 2025

Transform Your Cloud Infrastructure

Join PulumiUP 2025 on May 6 for Expert Insights & Demos.

Register Now

👋 Kindness is contagious

If you found this post helpful, please consider leaving a ❤️ or a kind comment!

Join a community of passionate developers and enhance your skills!