aboutsummaryrefslogtreecommitdiff
path: root/files/id/web/javascript/reference/operators/function
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 14:47:40 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 14:47:40 +0100
commitde6a111b5e7ec37c4965111a580217d0b1fd2736 (patch)
tree311c744a0d36b81c94ecc65a4429e8eb24a66aea /files/id/web/javascript/reference/operators/function
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-de6a111b5e7ec37c4965111a580217d0b1fd2736.tar.gz
translated-content-de6a111b5e7ec37c4965111a580217d0b1fd2736.tar.bz2
translated-content-de6a111b5e7ec37c4965111a580217d0b1fd2736.zip
unslug id: move
Diffstat (limited to 'files/id/web/javascript/reference/operators/function')
-rw-r--r--files/id/web/javascript/reference/operators/function/index.html153
1 files changed, 153 insertions, 0 deletions
diff --git a/files/id/web/javascript/reference/operators/function/index.html b/files/id/web/javascript/reference/operators/function/index.html
new file mode 100644
index 0000000000..5366891a5c
--- /dev/null
+++ b/files/id/web/javascript/reference/operators/function/index.html
@@ -0,0 +1,153 @@
+---
+title: ungkapan fungsi
+slug: Web/JavaScript/Reference/Operators/fungsi
+tags:
+ - Fungsi
+ - JavaScript
+ - Operator
+ - Ungkapan Utama
+translation_of: Web/JavaScript/Reference/Operators/function
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<div>Kata kunci <code><strong>fungsi</strong></code> digunakan untuk mendefinisikan <code><strong>fungsi</strong></code> dalam sebuah ungkapan<em>.</em></div>
+
+<div> </div>
+
+<h2 id="Sintaksis">Sintaksis</h2>
+
+<pre class="syntaxbox">function [<em>nama</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) {
+ pernyataan
+}</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>nama</code></dt>
+ <dd>Bisa dihilangkan apabila fungsi merupaka fungsi <em>anonim</em>. Nama fungsi bersifat lokal, relatif terhadap tubuh fungsi.</dd>
+ <dt><code>paramN</code></dt>
+ <dd>Nama argumen yang akan diumpankan kepada fungsi.</dd>
+ <dt><code>pernyataan</code></dt>
+ <dd>Pernyataan yang menyusun tubuh fungsi.</dd>
+</dl>
+
+<h2 id="Deskripsi">Deskripsi</h2>
+
+<p>Sintaksis ungkapan fungsi nyaris sama apabila dibandingkan dengan sintaksis pernyataan fungsi(lihat <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">pernyataan fungsi</a> untuk lebih jelasnya). Perbedaan utama antara ungkapan fungsi dengan pernyataan fungsi ialah; ungkapan fungsi memperbolehkan <em>nama fungsi </em>untuk tidak digunakan/dihilangkan apabila ungkapan fungsi tersebut merupakan fungsi <em>anonim</em>. Ungkapan fungsi dapat digunakan sebagai <em><strong>IIFE </strong>(immediately Invoked Function Expression)</em>, sebuah fungsi yang otomatis dijalankan apabila didefinisikan. Untuk informasi lebih lanjut, lihat juga bab tentang <a href="/en-US/docs/Web/JavaScript/Reference/Functions">fungsi</a>.</p>
+
+<h2 id="Contoh">Contoh</h2>
+
+<p>Dibawah ini merupakan contoh definisi sebuah fungsi tanpa nama yang kemudian ditugaskan kedalam variabel <code>x</code>:</p>
+
+<pre class="brush: js">var x = function(y) {
+ return y * y;
+};
+</pre>
+
+<h3 id="Ungkapan_fungsi_bernama_(Named_function_expression)">Ungkapan fungsi bernama (Named function expression)</h3>
+
+<p>Apabila sebuah fungsi hendak dipanggil dari dalam tubuh fungsi itu sendiri, pergunakanlah ungkapan fungsi bernama. Nama fungsi bersifat lokal relatif terhadap tubuh fungsi. Manfaat penggunaan ungkapan fungsi bernama ialah menghindarkan penggunaan properti non-standar <code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee">arguments.callee</a></code>.</p>
+
+<pre class="brush: js">var math = {
+ 'factorial': function factorial(n) {
+ if (n &lt;= 1)
+ return 1;
+ return n * factorial(n - 1);
+ }
+};
+</pre>
+
+<h2 id="Spesifikasi">Spesifikasi</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spesifikasi</th>
+ <th scope="col">Status</th>
+ <th scope="col">Komentar</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-function-definitions', 'Function definitions')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-13', 'Function definition')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3', '#sec-13', 'Function definition')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Definisi awal. Diterapkan pada JavaScript 1.5.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Kesesuaian_Perambah_(Browser)">Kesesuaian Perambah (Browser)</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Fitur</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Dukungan Mendasar</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Fitur</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Dukungan Mendasar</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Lihat_juga">Lihat juga</h2>
+
+<ul>
+ <li>{{jsxref("Functions_and_function_scope", "Functions and function scope")}}</li>
+ <li>{{jsxref("Function")}}</li>
+ <li>{{jsxref("Statements/function", "function statement")}}</li>
+ <li>{{jsxref("Statements/function*", "function* statement")}}</li>
+ <li>{{jsxref("Operators/function*", "function* expression")}}</li>
+ <li>{{jsxref("GeneratorFunction")}}</li>
+</ul>