InternalError: too much recursion

๋ฉ”์‹œ์ง€

InternalError: too much recursion

์—๋Ÿฌ ํ˜•์‹

InternalError.

๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ์„๊นŒ?

์ž์‹ ์„ ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์žฌ๊ท€ ํ•จ์ˆ˜๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์–ด๋–ค ๋ฉด์—์„œ, ์žฌ๊ท€๋Š” ๋ฐ˜๋ณต๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋‘˜ ๋‹ค ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ์‹คํ–‰ํ•˜๋ฉฐ, ์กฐ๊ฑด(๋ฌดํ•œ ๋ฐ˜๋ณต ํ”ผํ•˜๊ธฐ, ๋” ์ •ํ™•ํžˆ ์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” ๋ฌดํ•œ ์žฌ๊ท€)์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋„ˆ๋ฌด ๋งŽ๊ฑฐ๋‚˜ ๋ฌดํ•œ ๋ฒˆ์˜ ์žฌ๊ท€๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ, JavaScript๋Š” ์ด ์—๋Ÿฌ๋ฅผ ๋˜์งˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์˜ˆ

์ด ์žฌ๊ท€ ํ•จ์ˆ˜๋Š” exit ์กฐ๊ฑด์— ๋”ฐ๋ผ 10๋ฒˆ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

function loop(x) {
  if (x >= 10) // "x >= 10" is the exit condition
    return;
  // do stuff
  loop(x + 1); // the recursive call
}
loop(0);

์ด ์กฐ๊ฑด์— ๋Œ€ํ•˜์—ฌ ๋„ˆ๋ฌด ๋†’์€ ๊ฐ’์„ ์„ค์ • ํ•˜๋ฉด ์ž‘๋™ํ•˜์ง€ ์•Š๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

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

// InternalError: too much recursion

์ฐธ์กฐ