aboutsummaryrefslogtreecommitdiff
path: root/files/id/web/javascript/reference/errors/too_much_recursion
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
commitda78a9e329e272dedb2400b79a3bdeebff387d47 (patch)
treee6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/id/web/javascript/reference/errors/too_much_recursion
parent1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff)
downloadtranslated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip
initial commit
Diffstat (limited to 'files/id/web/javascript/reference/errors/too_much_recursion')
-rw-r--r--files/id/web/javascript/reference/errors/too_much_recursion/index.html70
1 files changed, 70 insertions, 0 deletions
diff --git a/files/id/web/javascript/reference/errors/too_much_recursion/index.html b/files/id/web/javascript/reference/errors/too_much_recursion/index.html
new file mode 100644
index 0000000000..4c35bcfc83
--- /dev/null
+++ b/files/id/web/javascript/reference/errors/too_much_recursion/index.html
@@ -0,0 +1,70 @@
+---
+title: 'InternalError: too much recursion'
+slug: Web/JavaScript/Reference/Errors/Too_much_recursion
+tags:
+ - Errors
+ - InternalError
+ - JavaScript
+translation_of: Web/JavaScript/Reference/Errors/Too_much_recursion
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="Pesan">Pesan</h2>
+
+<pre class="syntaxbox">Error: Out of stack space (Edge)
+InternalError: too much recursion (Firefox)
+RangeError: Maximum call stack size exceeded (Chrome)
+</pre>
+
+<h2 id="Tipe_error">Tipe error</h2>
+
+<p>{{jsxref("InternalError")}}.</p>
+
+<h2 id="Apa_yang_salah">Apa yang salah?</h2>
+
+<p>Fungsi yang memanggil dirinya sendiri disebut <em>fungsi rekursif</em>. Sekali satu kondisi telah ketemu, fungsi itu berhenti memanggil dirinya. Ini disebut <em>base case</em>.</p>
+
+<p>Dalam beberapa cara, rekursi analog dengan loop. Keduanya mengeksekusi kode yang sama berulang kali, dan keduanya membutuhkan satu kondisi (untuk mencegah loop tak-terbatas, atau lebih tepatnya, rekursi tak-terbatas dalam hal ini). <span class="seoSummary">Ketika panggilan fungsi terlalu banyak, atau tak ada base case dalam fungsi, JavaScript akan melempar error ini.</span></p>
+
+<h2 id="Contoh">Contoh</h2>
+
+<p>Fungsi rekursif ini berjalan 10 kali, per kondisi exit.</p>
+
+<pre class="brush: js">function loop(x) {
+ if (x &gt;= 10) // "x &gt;= 10" is the exit condition
+ return;
+ // do stuff
+ loop(x + 1); // the recursive call
+}
+loop(0);</pre>
+
+<p>Mengeset kondisi ini ke nilai extrem sangat tinggi, tak akan jalan:</p>
+
+<pre class="brush: js example-bad">function loop(x) {
+ if (x &gt;= 1000000000000)
+ return;
+ // do stuff
+ loop(x + 1);
+}
+loop(0);
+
+// InternalError: too much recursion</pre>
+
+<p>Fungsi rekursif ini tak punya base case. Jika tak kondisi exit, function akan memanggil dirinya sendiri terus-terusan.</p>
+
+<pre class="brush: js example-bad">function loop(x) {
+ // The base case is missing
+
+loop(x + 1); // Recursive call
+}
+
+loop(0);
+
+// InternalError: too much recursion</pre>
+
+<h2 id="Lihat_juga">Lihat juga</h2>
+
+<ul>
+ <li>{{Glossary("Rekursi")}}</li>
+ <li><a href="/en-US/docs/Web/JavaScript/Guide/Functions#Recursion">Fungsi rekursif</a></li>
+</ul>