There are many reasons why eval should be avoided, that it breaks scope is one of them. Passing a string to setTimeout causes it to be evaled when the timer runs out.

You should pass a function instead.

window.setTimeout(rotateImages(start+1),3000);

This calls rotateImages immediately, then passes its return value to setTimeout. This doesn't help since rotateImages doesn't return a function.

You probably want:

window.setTimeout(rotateImages,3000,[start+1]);

Or create an anonymous function that wraps a closure around start and pass that instead:

window.setTimeout(function () { rotateImages(start + 1); },3000);

The latter option has better support among browsers.

Answer from Quentin on Stack Overflow
🌐
TypeOfNaN
typeofnan.dev › why-is-my-recursive-function-returning-undefined-in-javascript
Why is My Recursive Function Returning Undefined in JavaScript? | TypeOfNaN
November 13, 2020 - We might write a recursive factorial function like this: function factorial(num, result = 1) { if (num === 1) { return result; } factorial(num - 1, num * result); } console.log(factorial(4)); // undefined · But this should be 24! Why is it undefined? Well the answer is easier than we think: we need to return the next execution of the factorial function each time or else we’ll never get to the ultimate result!
Discussions

recursion - JavaScript Recursive Callback Function - ReferenceError: function is not defined - Stack Overflow
The functional version lets you forget about all the strange this binding behavior. ... Sign up to request clarification or add additional context in comments. ... with your changes the recursion works. but a new problem has come up. stackoverflow.com/questions/20197553/… 2013-11-26T00:33:02.2Z+00:00 ... You need to read my code more carefully, note ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Recursive function returns undefined - Stack Overflow
This helped, but I'm interested in knowing why return is necessary for the recursion to operate correctly. 2019-03-25T00:04:27.71Z+00:00 ... If you want your function to return a value, then you must return a value. In javascript, a function without a return will return undefined. More on stackoverflow.com
🌐 stackoverflow.com
Recursive function returns undefined instead of the number
Write a function, persistence , that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit. let cou… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
August 31, 2022
javascript 'function not defined' error in recursion - Post.Byes
hi, i have a problem which recursion fits perfectly, however; after working with the base function (which has no errors and works correctly) the recursions return a "function not defined" error in ff's js console. i tried a few things that came to mind but nothing has changed it... i found ... More on post.bytes.com
🌐 post.bytes.com
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › advanced working with functions
Recursion and stack
When a function calls itself, that’s called a recursion step. The basis of recursion is function arguments that make the task so simple that the function does not make further calls. A recursively-defined data structure is a data structure that can be defined using itself.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript recursive function
JavaScript Recursive Function
November 15, 2024 - This tutorial shows you how to use the recursion technique to develop a JavaScript recursive function, which is a function that calls itself.
Find elsewhere
🌐
Post.Byes
post.bytes.com › home › forum › topic › javascript
javascript 'function not defined' error in recursion - Post.Byes
the second time i call value1(), when it is in the first loop of the recursive function, i get the 'function not defined' error. i also get a not defined error regarding the chars string on that same line if you get past the function error. i'm guessing its related... any help is appreciated. <script type="text/javascript"> var chars = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ"; function value1(baseChar , base, options) { this.baseChar = baseChar; this.base = base; if(options == "") this.valid = new Array(0); else { this.valid = new Array(0); for(var i=0; i<options.lengt h; i++)
🌐
Stack Overflow
stackoverflow.com › questions › 65293402 › typeerror-not-a-function-in-recursive-method-of-javascript-prototype
recursion - TypeError not a function in recursive method of Javascript prototype - Stack Overflow
VisualHelper.prototype.setManageMode = function (target, level=0) { var self = this; /* Some operations ......*/ target.children(":not(.Vhelper_button)").each(function (){ console.log(self) console.log(self.setManageMode) self.setManageMode($(this), level+1) }) } I have created a class called VisualHelper and one of its prototype methods as shown in the code snippet, with irrelevant parts omitted. The method takes a Jquery Object target and a int value level. My problem is, inside the recursion part, target.children.each(...), the variable self got referenced to Window instead of the object this, and then I got self.setManageMode is not a function TypeError.
🌐
Stack Overflow
stackoverflow.com › questions › 45418558 › protractor-recursive-function-error-function-not-defined
javascript - Protractor recursive function error: Function not defined - Stack Overflow
July 31, 2017 - It's just this method called recursively that I am not able to run successfully. ... If it's within a class, you forgot to add the this keyword to the method invocation. Should be array.concat(this.getAllComponents()). ... I was definitely missing the 'this' keyword, thanks!
🌐
Reddit
reddit.com › r/javascript › recursive function is returning "undefined"
r/javascript on Reddit: Recursive function is returning "undefined"
December 30, 2017 -

I have a recursive function that seems to be returning undefined even though console.log indicates that the return statement in the function should have a value.

function fearNotLetter(str) {

    function checkChar(char) {
	    var tempStr = str.split("");
	    if (tempStr[char + 1] == String.fromCharCode(tempStr[char].charCodeAt(0) + 1)) {
                checkChar(char + 1);
	     } else {
		    console.log(String.fromCharCode(tempStr[char].charCodeAt(0) + 1));
		    return String.fromCharCode(tempStr[char].charCodeAt(0) + 1);
	    }
    }

    console.log(checkChar(0));
}

My first console.log statement indicates that the statement does get the value I'm expecting, but when I return that value, my second console.log statement gives me "undefined".

🌐
DEV Community
dev.to › kalashin1 › recursive-functions-in-javascript-b6a
Recursive Functions In JavaScript - DEV Community
August 13, 2022 - We have a bare minimum of an implementation of a recursive function, we declare a function doSomething and inside of it we call doSomething again. If you are quite experienced writing code, you'd know that the function we have defined above will cause the JavaScript runtime to throw a stack overflow error.
🌐
Sololearn
sololearn.com › en › Discuss › 1168078 › recursive-function-returning-undefined
Recursive function returning undefined | Sololearn: Learn to code for FREE!
Thanks! function iterObj(obj){ for (var key in obj){ console.log (key + ":" + obj[key]); if (obj[key] !== null && typeof obj[key] === 'object'){ return iterObj(obj[key]); } } } var solo = iterObj(argument) // nested objects solo // undefined https://code.sololearn.com/W675Ao227f7B/?ref=app · javascriptfunctionrecursive · 25th Mar 2018, 5:15 PM · Akuoma Joshua · 2 Answers · Answer · + 3 · "argument" is not defined in your js ·