Recursive code explained

Hi, I am reading Eloquent JS book and I just did recursive function exercise. I did this on my own and it works, but I still have problems to get how recursion works, could anyone explain me this code line by line please? Obviously, only part on line 7 is confusing for me, everything else is ok.

function isEven(n) {
  if (n == 0) {
    return true;
  } else if (n == 1) {
    return false;
  } else {
    return isEven(n - 2);

The code on line 7 is where the function is infinitely calling itself until a base-case is met (the recursive step). What this does is create a stack of function calls that stack up until the base-case is met, and then unstack as each function call resolves the one that came before it:

1 Like

Hey @Ivan999, Iā€™m also a bit confused by line 7, in particular, is -2 even or odd?