diff options
Diffstat (limited to 'files/id/web/javascript/reference/operators')
4 files changed, 0 insertions, 699 deletions
diff --git a/files/id/web/javascript/reference/operators/conditional_operator/index.html b/files/id/web/javascript/reference/operators/conditional_operator/index.html deleted file mode 100644 index 1a64158acb..0000000000 --- a/files/id/web/javascript/reference/operators/conditional_operator/index.html +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: Operasional Kondisi (ternary) -slug: Web/JavaScript/Reference/Operators/Conditional_Operator -translation_of: Web/JavaScript/Reference/Operators/Conditional_Operator ---- -<div>{{jsSidebar("Operators")}}</div> - -<p><strong>Operasianal kondisional (ternary)</strong> adalah satu-satunya operator yang hanya membutuhkan tiga operator. Operator ini sering digunakan sebagai jalan pintas untuk `if` statement.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><em>condition</em> ? <em>expr1</em> : <em>expr2</em> </pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>condition (atau conditions)</code></dt> - <dd>Sebuah ekspresi akan menguji apakah menghasilkan <code>true</code> atau <code>false</code>.</dd> -</dl> - -<dl> - <dt><code>expr1</code>, <code>expr2</code></dt> - <dd>Ekspresi yang akan dilakukan setelah kondisi terpenuhi.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p>Jika <code>condition</code> menghasilkan <code>true</code>, maka operator ini akan menghasilkan/mengembalikan nilai dari <code>expr1</code>; dan jika sebaliknya, ini akan menghasilkan/mengembalikan nilai dari <code>expr2</code>. Sebagai contoh, untuk menampilkan pesan yang berbeda berdasarkan nilai dari variabel <code>isMember</code>, anda bisa menggunakan contoh kode berikut:</p> - -<pre class="brush: js">var isMember = true; -'The fee is ' + (isMember ? '$2.00' : '$10.00'); //$2.00 -</pre> - -<p>Anda juga dapat mendefinisikan sebuah variabel secara langsung:</p> - -<pre class="brush: js">var elvisLives = Math.PI > 4 ? 'Yep' : 'Nope';</pre> - -<p>Anda juga bisa menggunakan operator ternary secara jamak (catatan: conditional operator adalah associative yang lebih baik):</p> - -<pre class="syntaxbox">var firstCheck = false, secondCheck = false, access = firstCheck ? 'Access denied' : secondCheck ? 'Access denied' : 'Access granted'; -console.log(access); // logs "Access granted"</pre> - -<p>Anda juga dapat menggunakan pengondisian jamak seperti pengondisian jamak pada statement IF pada umumnya:</p> - -<pre class="syntaxbox">var condition1 = true, - condition2 = false, - access = condition1 ? (condition2 ? "true true": "true false") : (condition2 ? "false true" : "false false"); - -console.log(access); // logs "true false" -</pre> - -<p> </p> - -<p>Note: The parentheses are not required, and do not affect the functionality. They are there to help visualize how the outcome is processed.</p> - -<p>You can also use ternary evaluations in free space in order to do different operations:</p> - -<pre class="brush: js">var stop = false, age = 16; - -age > 18 ? location.assign('continue.html') : stop = true; -</pre> - -<p>You can also do more than one single operation per case, separating them with a comma, and enclosing them in parenthesis:</p> - -<pre class="brush: js">var stop = false, age = 23; - -age > 18 ? ( - alert('OK, you can go.'), - location.assign('continue.html') -) : ( - stop = true, - alert('Sorry, you are much too young!') -); -</pre> - -<p>You can also do more than one operation during the assignation of a value. In this case, <strong><em>the last comma-separated value of the parenthesis</em> will be the value to be assigned</strong>.</p> - -<pre class="brush: js">var age = 16; - -var url = age > 18 ? ( - alert('OK, you can go.'), - // alert returns "undefined", but it will be ignored because - // isn't the last comma-separated value of the parenthesis - 'continue.html' // the value to be assigned if age > 18 -) : ( - alert('You are much too young!'), - alert('Sorry :-('), - // etc. etc. - 'stop.html' // the value to be assigned if !(age > 18) -); - -location.assign(url); // "stop.html"</pre> - -<h3 id="Returning_Ternary_Statements">Returning Ternary Statements</h3> - -<p>The ternary operator lends itself well to function returns that would otherwise require an <code>if/else</code> statement.</p> - -<pre class="brush: js">var func1 = function( .. ) { - if (condition1) { return value1 } - else { return value2 } -} - -var func2 = function( .. ) { - return condition1 ? value1 : value2 -}</pre> - -<p>A good way to spot that the ternary will be a suitable replacement for an <code>if/else</code> statement is when the <code>return</code> keyword is used multiple times and is the only expression inside of the if block.</p> - -<p>By breaking the ternary onto multiple lines and making use of extra whitespace, the ternary operator can be used to very cleanly replace a lengthy series of <code>if/else</code> statements. This provides a syntactically light way of expressing the same logic:</p> - -<pre class="brush: js">var func1 = function( .. ) { - if (condition1) { return value1 } - else if (condition2) { return value2 } - else if (condition3) { return value3 } - else { return value4 } -} - -var func2 = function( .. ) { - return condition1 ? value1 - : condition2 ? value2 - : condition3 ? value3 - : value4 -}</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-conditional-operator', 'Conditional Operator')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-conditional-operator', 'Conditional Operator')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11.12', 'The conditional operator')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES1', '#sec-11.12', 'The conditional operator')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initial definition. Implemented in JavaScript 1.0.</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - - - -<p>{{Compat("javascript.operators.conditional")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else">if statement</a></li> -</ul> diff --git a/files/id/web/javascript/reference/operators/function/index.html b/files/id/web/javascript/reference/operators/function/index.html deleted file mode 100644 index 7fa9564333..0000000000 --- a/files/id/web/javascript/reference/operators/function/index.html +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: ungkapan fungsi -slug: Web/JavaScript/Reference/Operators/function -tags: - - Fungsi - - JavaScript - - Operator - - Ungkapan Utama -translation_of: Web/JavaScript/Reference/Operators/function -original_slug: Web/JavaScript/Reference/Operators/fungsi ---- -<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 <= 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> diff --git a/files/id/web/javascript/reference/operators/index.html b/files/id/web/javascript/reference/operators/index.html deleted file mode 100644 index ef3afeb763..0000000000 --- a/files/id/web/javascript/reference/operators/index.html +++ /dev/null @@ -1,269 +0,0 @@ ---- -title: Expressions and operators -slug: Web/JavaScript/Reference/Operators -tags: - - JavaScript - - NeedsTranslation - - Operators - - TopicStub -translation_of: Web/JavaScript/Reference/Operators ---- -<div>{{jsSidebar("Operators")}}</div> - -<p>This chapter documents all the JavaScript language operators, expressions and keywords.</p> - -<h2 id="Ekspresi_and_operator_sesuai_kategori">Ekspresi and operator sesuai kategori</h2> - -<p>Untuk daftar isi sesuai Alfabet, silahkan lihat sisi sebelah kiri artikel ini.</p> - -<h3 id="Primary_expressions">Primary expressions</h3> - -<p>Basic keywords and general expressions in JavaScript.</p> - -<p>Keyword-keyword dasar dan ekspersi-ekspresi umum di javascript</p> - -<dl> - <dt>{{jsxref("Operators/this", "this")}}</dt> - <dd>The <code>this</code> keyword refers to the function's execution context.</dd> - <dt>{{jsxref("Operators/function", "function")}}</dt> - <dd>The <code>function</code> keyword defines a function expression.</dd> - <dt>{{jsxref("Global_Objects/Array", "[]")}}</dt> - <dd>Array literal syntax.</dd> - <dt>{{jsxref("Global_Objects/Object", "{}")}}</dt> - <dd>Object literal syntax.</dd> - <dt>{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}</dt> - <dd>Regular expression literal syntax.</dd> - <dt>{{experimental_inline()}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}</dt> - <dd>Array comprehensions.</dd> - <dt>{{experimental_inline()}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}</dt> - <dd>Generator comprehensions.</dd> - <dt>{{jsxref("Operators/Grouping", "( )")}}</dt> - <dd>Grouping operator.</dd> -</dl> - -<h3 id="Left-hand-side_expressions">Left-hand-side expressions</h3> - -<p>Left values are the destination of an assignment.</p> - -<dl> - <dt>{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}</dt> - <dd>Member operators provide access to a property or method of an object<br> - (<code>object.property</code> and <code>object["property"]</code>).</dd> - <dt>{{jsxref("Operators/new", "new")}}</dt> - <dd>The <code>new</code> operator creates an instance of a constructor.</dd> - <dt>{{experimental_inline()}} {{jsxref("Operators/super", "super")}}</dt> - <dd>The <code>super</code> keyword calls the parent constructor.</dd> - <dt>{{experimental_inline()}} {{jsxref("Operators/Spread_operator", "...obj")}}</dt> - <dd>The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.</dd> -</dl> - -<h3 id="Increment_and_decrement">Increment and decrement</h3> - -<p>Postfix/prefix increment and postfix/prefix decrement operators.</p> - -<dl> - <dt>{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}</dt> - <dd>Postfix increment operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}</dt> - <dd>Postfix decrement operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}</dt> - <dd>Prefix increment operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}</dt> - <dd>Prefix decrement operator.</dd> -</dl> - -<h3 id="Unary_operators">Unary operators</h3> - -<p>A unary operation is operation with only one operand.</p> - -<dl> - <dt>{{jsxref("Operators/delete", "delete")}}</dt> - <dd>The <code>delete</code> operator deletes a property from an object.</dd> - <dt>{{jsxref("Operators/void", "void")}}</dt> - <dd>The <code>void</code> operator discards an expression's return value.</dd> - <dt>{{jsxref("Operators/typeof", "typeof")}}</dt> - <dd>The <code>typeof</code> operator determines the type of a given object.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}</dt> - <dd>The unary plus operator converts its operand to Number type.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}</dt> - <dd>The unary negation operator converts its operand to Number type and then negates it.</dd> - <dt>{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}</dt> - <dd>Bitwise NOT operator.</dd> - <dt>{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}</dt> - <dd>Logical NOT operator.</dd> -</dl> - -<h3 id="Arithmetic_operators">Arithmetic operators</h3> - -<p>Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.</p> - -<dl> - <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}</dt> - <dd>Addition operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}</dt> - <dd>Subtraction operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}</dt> - <dd>Division operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}</dt> - <dd>Multiplication operator.</dd> - <dt>{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}</dt> - <dd>Remainder operator.</dd> -</dl> - -<h3 id="Relational_operators">Relational operators</h3> - -<p>A comparison operator compares its operands and returns a <code>Boolean</code> value based on whether the comparison is true.</p> - -<dl> - <dt>{{jsxref("Operators/in", "in")}}</dt> - <dd>The <code>in</code> operator determines whether an object has a given property.</dd> - <dt>{{jsxref("Operators/instanceof", "instanceof")}}</dt> - <dd>The <code>instanceof</code> operator determines whether an object is an instance of another object.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}</dt> - <dd>Less than operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}</dt> - <dd>Greater than operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}</dt> - <dd>Less than or equal operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}</dt> - <dd>Greater than or equal operator.</dd> -</dl> - -<h3 id="Equality_operators">Equality operators</h3> - -<p>The result of evaluating an equality operator is always of type <code>Boolean</code> based on whether the comparison is true.</p> - -<dl> - <dt>{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}</dt> - <dd>Equality operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}</dt> - <dd>Inequality operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}</dt> - <dd>Identity operator.</dd> - <dt>{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}</dt> - <dd>Nonidentity operator.</dd> -</dl> - -<h3 id="Bitwise_shift_operators">Bitwise shift operators</h3> - -<p>Operations to shift all bits of the operand.</p> - -<dl> - <dt>{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}</dt> - <dd>Bitwise left shift operator.</dd> - <dt>{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}</dt> - <dd>Bitwise right shift operator.</dd> - <dt>{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}</dt> - <dd>Bitwise unsigned right shift operator.</dd> -</dl> - -<h3 id="Binary_bitwise_operators">Binary bitwise operators</h3> - -<p>Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.</p> - -<dl> - <dt>{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}</dt> - <dd>Bitwise AND.</dd> - <dt>{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}</dt> - <dd>Bitwise OR.</dd> - <dt>{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}</dt> - <dd>Bitwise XOR.</dd> -</dl> - -<h3 id="Binary_logical_operators">Binary logical operators</h3> - -<p>Logical operators are typically used with boolean (logical) values, and when they are, they return a boolean value.</p> - -<dl> - <dt>{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}</dt> - <dd>Logical AND.</dd> - <dt>{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}</dt> - <dd>Logical OR.</dd> -</dl> - -<h3 id="Conditional_(ternary)_operator">Conditional (ternary) operator</h3> - -<dl> - <dt>{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}</dt> - <dd> - <p>The conditional operator returns one of two values based on the logical value of the condition.</p> - </dd> -</dl> - -<h3 id="Assignment_operators">Assignment operators</h3> - -<p>An assignment operator assigns a value to its left operand based on the value of its right operand.</p> - -<dl> - <dt>{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}</dt> - <dd>Assignment operator.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}</dt> - <dd>Multiplication assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}</dt> - <dd>Division assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}</dt> - <dd>Remainder assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}</dt> - <dd>Addition assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}</dt> - <dd>Subtraction assignment</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}</dt> - <dd>Left shift assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}</dt> - <dd>Right shift assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}</dt> - <dd>Unsigned right shift assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}</dt> - <dd>Bitwise AND assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}</dt> - <dd>Bitwise XOR assignment.</dd> - <dt>{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}</dt> - <dd>Bitwise OR assignment.</dd> - <dt>{{experimental_inline()}} {{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}<br> - {{experimental_inline()}} {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}</dt> - <dd> - <p>Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.</p> - </dd> -</dl> - -<h3 id="Comma_operator">Comma operator</h3> - -<dl> - <dt>{{jsxref("Operators/Comma_Operator", ",")}}</dt> - <dd> - <p>The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.</p> - </dd> -</dl> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>ECMAScript 1st Edition.</td> - <td>Standard</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11', 'Expressions')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>New: Spread operator, destructuring assignment, <code>super</code> keyword, Array comprehensions, Generator comprehensions</td> - </tr> - </tbody> -</table> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">Operator precedence</a></li> -</ul> diff --git a/files/id/web/javascript/reference/operators/yield/index.html b/files/id/web/javascript/reference/operators/yield/index.html deleted file mode 100644 index 366f2aaa38..0000000000 --- a/files/id/web/javascript/reference/operators/yield/index.html +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: yield -slug: Web/JavaScript/Reference/Operators/yield -translation_of: Web/JavaScript/Reference/Operators/yield ---- -<div>{{jsSidebar("Operators")}}</div> - -<p>Keyword <code>yield</code> digunakan untuk menghentikan sementara dan melanjutkan sebuah fungsi generator ({{jsxref("Statements/function*", "function*")}} atau <a href="/en-US/docs/Web/JavaScript/Reference/Statements/Legacy_generator_function">legacy generator function</a>).</p> - -<h2 id="Sintak">Sintak</h2> - -<pre class="syntaxbox notranslate">[<em>rv</em>] = <strong>yield</strong> [<em>expression</em>];</pre> - -<dl> - <dt><code>expression</code></dt> - <dd>Mendefeniskan nilai yang akan dikembalikan melalui <a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol">iterator protocol</a>. Apabila diabaikan, maka <code>undefined</code> akan dikembalikan.</dd> - <dt><code>rv</code></dt> - <dd> - <p>Mengembalikan nilai opsional yang diberikan pada generator method <code>next()</code> untuk melanjutkan eksekusinya.</p> - </dd> -</dl> - -<h2 id="Deskripsi">Deskripsi</h2> - -<p>Keyword <code>yield </code>menghentikan secara sementara eksekusi dari fungsi generator dan nilai setelah keyword <code>yield</code> dikembalikan pada pemanggil generator tersebut. <code>yield</code> bisa juga disebut sebagai versi generator dari keyword<code>return</code>.</p> - -<p>Keyword <code>yield</code> sebenarnya mengembalikan sebuah obyek <code>IteratorResult</code> dengan dua properti, <code>value</code> dan <code>done</code>. Properti<code>value</code> adalah hasi dari evaluasi ekspresi <code>yield</code>, dan <code>done</code> yang <code>false</code>, mengindikasikan bahwa fungsi generator tersebut belum selesai sepenuhnya.</p> - -<p>Sekali berhenti pada ekspresi <code>yield</code> , eksekusi dari code generator tersebut akan terus dihentikan sampai generator method <code>next()</code> dipanggil. Setiap kali method generator <code>next()</code> dipanggil, generator melanjutkan eksekusi dan berjalan hingga mencapai salah satu dari kondisi berikut ini :</p> - -<ul> - <li>Sebuah<code>yield</code>, yang menyebabkan generator sekali lagi berhenti sementara dan mengembalikan nilai baru dari generator tersebut. Ketika kemudian<code>next()</code> dipanggil lagi, eksekusi berlanjut dengan statement segera setelah<code>yield</code>.</li> - <li>{{jsxref("Statements/throw", "throw")}} digunakan untuk melontarkan exception dari generator. Ini menghentikan generator sepenuhnya, dan eksekusi berlanjut pada pemanggil seperti normalnya ketika sebuah exception dilontarkan.</li> - <li>Akhir dari fungsi generator tersebut tercapai; pada kasus ini, eksekusi dari generator tersebut berakhir dan sebuah <code>IteratorResult</code> dikembalikan pada pemanggilnya dimana <code>value</code> adalah {{jsxref("undefined")}} dan <code>done</code> adalah <code>true</code>.</li> - <li>Mencapai sebuah statement {{jsxref("Statements/return", "return")}}. Pada kasus ini, eksekusi dari generator tersebut berakhir dan sebuah <code>IteratorResult</code> dikembalikan pada pemanggil dimana <code>value</code> ditentukan oleh statement <code>return</code> dan <code>done</code> adalah <code>true</code>.</li> -</ul> - -<p>JIka sebuah nilai opsional diberikan pada generator method <code>next()</code>, nilai tersebut menjadi nilai yang dikembalikan oleh operasi <code>yield</code> dari generator pada saat itu.</p> - -<p>Di antara kode generator, operator<code>yield</code> -nya, dan kemampuan untuk menentukan sebua nilai awal baru dengan memberikannya pada {{jsxref("Generator.prototype.next()")}}, generator menawarkan power dan kontrol yang luar biasa.</p> - -<h2 id="Contoh">Contoh</h2> - -<p>Kode berikut merupakan deklarasi dari sebuah contoh fungsi generator.</p> - -<pre class="brush: js notranslate">function* countAppleSales () { - var saleList = [3, 7, 5]; - for (var i = 0; i < saleList.length; i++) { - yield saleList[i]; - } -}</pre> - -<p>Setelah sebuah fungsi generator didefenisikan, maka fungsi tersebut dapat digunakan untuk menghasilkan sebuah iterator seperti berikut.</p> - -<pre class="brush: js notranslate">var appleStore = countAppleSales(); // Generator { } -console.log(appleStore.next()); // { value: 3, done: false } -console.log(appleStore.next()); // { value: 7, done: false } -console.log(appleStore.next()); // { value: 5, done: false } -console.log(appleStore.next()); // { value: undefined, done: true }</pre> - -<h2 id="Spesifikasi">Spesifikasi</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Spesifikasi</th> - <th scope="col">Status</th> - <th scope="col">Komentar</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ES2015', '#', 'Yield')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#', 'Yield')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Kompatabilitas_Browser">Kompatabilitas Browser</h2> - -<div class="hidden">Tabel kompatabilitas ini dihasilkan dari struktur data. Jika anda ingin berkontribusi pada data, silahkan lihat <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> dan kirimkan kami sebuah pull request.</div> - -<p>{{Compat("javascript.operators.yield")}}</p> - -<h2 id="Catatan_Firefox-specific">Catatan Firefox-specific</h2> - -<ul> - <li>Semenjak Gecko 29 {{geckoRelease(29)}}, the completed generator function no longer throws a {{jsxref("TypeError")}} "generator has already finished". Instead, it returns an <code>IteratorResult</code> object like <code>{ value: undefined, done: true }</code> ({{bug(958951)}}).</li> - <li>Starting with Gecko 33 {{geckoRelease(33)}}, the parsing of the <code>yield</code> expression has been updated to conform with the ES2015 specification ({{bug(981599)}}): - <ul> - <li>The expression after the <code>yield</code> keyword is optional and omitting it no longer throws a {{jsxref("SyntaxError")}}: <code>function* countAppleSales() { yield; }</code></li> - </ul> - </li> -</ul> - -<h2 id="Lihat_juga">Lihat juga</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">The Iterator protocol</a></li> - <li>{{jsxref("Statements/function*", "function*")}}</li> - <li>{{jsxref("Operators/function*", "function* expression")}}</li> - <li>{{jsxref("Operators/yield*", "yield*")}}</li> -</ul> |