Closed Bug 1694815 Opened 5 years ago Closed 5 years ago

Not using 'var' keyword in Javascript for loop inside recursive function causes infinite loop

Categories

(Firefox :: Untriaged, defect)

78 Branch
defect

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: ggrantward, Unassigned, NeedInfo)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Steps to reproduce:

function recurse(someValue) {
if (someValue) {
for (i=0; i<5; i++) {
recurse(someAction(someValue));
}
}
}

Actual results:

Infinite loop that was not stoppable and crashed my computer

Expected results:

variable i should have been local to the function and isolated from subsequent calls, however it was overwritten by each subsequent recursion

The code example is wrong. The loop will not occur with a set value as in i<5, it will only happen in a dynamic case such as element.children.length.

Hi,

Since the example is wrong, could you attach another example, like done in bug#1694740? Or upload the code to any other platform and share it with us, please.

Thanks, Flor.

Flags: needinfo?(ggrantward)

Hi ggrantward,

Are you still experiencing the issue?

In the mean time I'll mark this as Resolved-Incomplete due to lack of information. If the issue is still reproducible with the latest Firefox version, please feel free to reopen the bug with more information (such as steps to reproduce, or sample test page).

Thanks in advance,
Virginia

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.