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.