
Sparky E. answered 07/08/19
Software Engineer @ J.P. Morgan Chase & Co.
In this function you are declaring a variable inside a function. In that same function you return another function that references the x in the previous function and increments it by one. The first problem that you are having is that the second function doesn't know about that x variable because it is encapsulated in the first function. The second problem that you are having is that the first return is returning a function when it should return a value and it is going to come up as undefined. The second return statement does not fire at all since the algorithm does not reach that statement.