---
title: "Discussion on \"Js 不导致栈溢出的递归函数\" | Hashnode"
description: "Discussion on \"Js 不导致栈溢出的递归函数\". 堆栈溢出\n递归函数（Recursive Function）如果调用自身次数过多，超过栈大小限制，就会导致栈溢出。\n一个典型的例子是，用递归函数简陋实现斐波那契数列，如果调用参数过大，将导致栈溢出：\nfunction fibonacci(n) {\n  if (n < 2) return n;\n  return fibonacci(n - 1) + fibonacci(n - 2);\n}\n\nfor (let n = 0; n < 100; n++) {\n  console.log(`fibo ${n..."
url: "https://hashnode.com/posts/recursive-functions-dont-casue-stack-overflow-in-js-cn/65ae33f78ce8d4c849cabf06"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Js 不导致栈溢出的递归函数](https://blog.iread.fun/recursive-functions-dont-casue-stack-overflow-in-js-cn?utm_source=hashnode&utm_medium=feed)

堆栈溢出 递归函数（Recursive Function）如果调用自身次数过多，超过栈大小限制，就会导致栈溢出。 一个典型的例子是，用递归函数简陋实现斐波那契数列，如果调用参数过大，将导致栈溢出： function fibonacci(n) { if (n < 2) return n; return fibonacci(n - 1) + fibonacci(n - 2); } for (let n = 0; n < 100; n++) { console.log(\`fibo ${n...

Jan 22, 2024 · 1 min read · blog.iread.fun  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#recursive-function](https://hashnode.com/tag/recursive-function)
-   [#asynchronous-javascript](https://hashnode.com/tag/asynchronous-javascript)
-   [#tail-call-optimization](https://hashnode.com/tag/tail-call-optimization)
-   [#call-stack](https://hashnode.com/tag/call-stack)

## Written by

[v like](https://hashnode.com/@likev)

@likev

  
[View profile](https://hashnode.com/@likev)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
