pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Errors/Too_much_recursion

" href="https://developer.mozilla.org/favicon.svg" />

Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.

View in English Always switch to English

InternalError: too much recursion

Mensagem

Error: Out of stack space (Edge)
InternalError: too much recursion (Firefox)
RangeError: Maximum call stack size exceeded (Chrome)

Tipo de erro

InternalError.

O que deu errado?

Uma função que invoca a si mesma é chamada função recursiva. Assim que uma condição é atendida, a função para de se invocar.

De certa forma, recursão é análoga a um loop. Ambos executam o mesmo código múltiplas vezes, e ambos exigem uma condição (para evitar um loop infinito ou, nesse caso, uma recursão infinita). Quando são feitas excessivas invocações, ou a função não possui uma condição para interromper a recursividade, este erro é lançado.

Exemplos

Esta função recursiva roda 10 vezes, como definido pela condição de saída.

js
function loop(x) {
  if (x >= 10) {
    // "x >= 10" é a condição de saída
    return;
  }
  loop(x + 1); // o código recursivo em si
}
loop(0);

Mudar esta condição para um valor extremamente alto não vai funcionar:

js
function loop(x) {
  if (x >= 1000000000000) return;
  loop(x + 1);
}
loop(0);

// InternalError: too much recursion

A seguinte função recursiva não possui condição de saída. Assim, ela vai continuar se invocando indefinidamente (até que o erro seja lançado e a execução interrom).

js
function loop(x) {
  // Não há condição de saída

  loop(x + 1); // Código recursivo
}

loop(0);

// InternalError: too much recursion

Veja também

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy