Can you explain to me what is wrong?


#1

Can you explain to me what is wrong with this code because I'm pretty sure there's something wrong because it says "Out of stack space"

var isEven = function(number) {
  if(isEven(8))
  {
      return true
  }
  else
  {
      return false
  }
  
};

#2

The short story:

if(isEven(8))

should better check whether number is even or not. Hint: modulo operator.

The long story what: "Out of stack space" means.
A function is some sort of sub-program that is started with a function call and that interrupts the current program when started. So if a normal program is a sheet of tasks then a function is a new sheet with higher priority. Now as any function has it's own set of variables it needs some space in the memory so the overall number of possible sheets is limited. Normally this is not a problem as it is at about a few ten thousand if you've a decent PC and internet connection. Also it decreases if you're done with the function. But in this case you've created some kind of infinite loop of calling function as you could see:

isEven is called for the first time:
Enter the function can encounter:
 if(isEven(8))
in order to evaluate isEven(8) you call isEven and encounter:
 if(isEven(8))
in order to evaluate isEven(8) you call isEven and encounter:
 if(isEven(8))
...

So due to this infinite loop you reach the maximum number of functions.