Sign in
Log inSign up

How the recursion is working in the following code?

Bhojendra Rauniyar's photo
Bhojendra Rauniyar
·Feb 19, 2019

Can anyone please explain this code?

(function f(){
  function f(){ return 1; }
  return f();
  function f(){ return 2; }
})();

I really didn't understand the recursion. I thought it will return 1 because it already returned f(), but it returned 2.

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct