You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/07-operators/article.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -280,7 +280,7 @@ Apakah ada perbedaan? Ya, tapi kita cuma bisa melihatnya jika kita menggunakan n
280
280
281
281
Mari kita klarifikasi. Seperti yang kita tahu, semua operator mengembalikan nilai. Inkremen/dekremen bukan pengecualian. Bentuk prefix mengembalikan nilai baru sedangkan bentuk postfix mengembalikan nilai lama (sebelum inkremen/dekremen).
282
282
283
-
Untuk melihat perbedaannya, berikut contohnya:
283
+
Untuk melihat perbedaannya, berikut misalnya:
284
284
285
285
```js run
286
286
let counter =1;
@@ -305,7 +305,7 @@ Dalam barus `(*)`, bentuk *postfix* `counter++` juga menginkremen `counter` tapi
305
305
306
306
Ringkasnya:
307
307
308
-
- Jika hasil dari inkremen/dekremen tidak digunakan, tak ada perbedaan bentuk mana yang dipakai:
308
+
- Jika hasil dari inkremen/dekremen tak digunakan, tak ada bedanya bentuk mana yang dipakai:
309
309
310
310
```js run
311
311
let counter = 0;
@@ -319,33 +319,33 @@ Ringkasnya:
319
319
let counter = 0;
320
320
alert( ++counter ); // 1
321
321
```
322
-
-If we'd like to increment a value but use its previous value, we need the postfix form:
322
+
-Jika kita ingin menginkremen suatu nilai tanpa memakai nilai sebelumnya, kita butuh bentuk postfix:
323
323
324
324
```js run
325
325
let counter = 0;
326
326
alert( counter++ ); // 0
327
327
```
328
328
329
-
````smart header="Increment/decrement among other operators"
330
-
The operators `++/--` can be used inside expressions as well. Their precedence is higher than most other arithmetical operations.
329
+
````smart header="Inkremen/dekremen di antara operator lainnya"
330
+
Operator `++/--`bisa juga digunakan di dalam expresi. Presedensi mereka lebih tinggi dari kebanyakan operasi aritmatika lainnya.
331
331
332
-
For instance:
332
+
Misalnya:
333
333
334
334
```js run
335
335
let counter = 1;
336
336
alert( 2 * ++counter ); // 4
337
337
```
338
338
339
-
Compare with:
339
+
Bandingkan dengan:
340
340
341
341
```js run
342
342
let counter = 1;
343
-
alert( 2 * counter++ ); // 2, because counter++ returns the "old" value
343
+
alert( 2 * counter++ ); // 2, karena counter++ mengembalikan nilai "lama"
344
344
```
345
345
346
-
Though technically okay, such notation usually makes code less readable. One line does multiple things -- not good.
346
+
Meski secara teknis OK, notasi macam ini biasanya membuat kode kurang dapat dibaca. Satu baris melakukan banyak hal--tak baik.
347
347
348
-
While reading code, a fast "vertical" eye-scan can easily miss something like `counter++` and it won't be obvious that the variable increased.
348
+
Sambil membaca kode, a fast "vertical" eye-scan can easily miss something like `counter++` and it won't be obvious that the variable increased.
349
349
350
350
We advise a style of "one line -- one action":
351
351
@@ -356,13 +356,13 @@ counter++;
356
356
```
357
357
````
358
358
359
-
## Bitwise operators
359
+
## Operator bitwise
360
360
361
-
Bitwise operators treat arguments as 32-bit integer numbers and work on the level of their binary representation.
361
+
Operator bitwise memperlakukan argumen sebagai angka integer 32-bit dan bekerja pada level representasi biner mereka.
362
362
363
-
These operators are not JavaScript-specific. They are supported in most programming languages.
363
+
Operator ini bukan spesifik JavaScript. Mereka didukung di banyak bahasa pemrograman.
364
364
365
-
The list of operators:
365
+
Daftar operator:
366
366
367
367
- AND ( `&` )
368
368
- OR ( `|` )
@@ -372,77 +372,77 @@ The list of operators:
372
372
- RIGHT SHIFT ( `>>` )
373
373
- ZERO-FILL RIGHT SHIFT ( `>>>` )
374
374
375
-
These operators are used very rarely. To understand them, we need to delve into low-level number representation and it would not be optimal to do that right now, especially since we won't need them any time soon. If you're curious, you can read the [Bitwise Operators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) article on MDN. It would be more practical to do that when a real need arises.
375
+
Operator ini sangat jarang digunakan. Untuk memahami mereka, kita harus menyelidiki lebih dalam representasi angka level-rendah dan itu tak akan optimal untuk dilakukan sekarang, terutama karena kita tak butuh mereka sesegera ini. Kalau kamu penasaran, kamu bisa baca artikel [Operator Bitwise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) di MDN. Itu akan lebih praktis untuk dilakukan ketika ada kebutuhan riil.
376
376
377
-
## Modify-in-place
377
+
## Modifikasi di tempat
378
378
379
-
We often need to apply an operator to a variable and store the newresultin that same variable.
379
+
Kita sering wajib mengaplikasikan operator ke variabel dan menyimpan hasilnya di variabel yang sama.
380
380
381
-
For example:
381
+
Misalnya:
382
382
383
383
```js
384
384
let n = 2;
385
385
n = n + 5;
386
386
n = n * 2;
387
387
```
388
388
389
-
This notation can be shortened using the operators`+=` and `*=`:
389
+
Notasi ini bisa dipersingkat menggunakan operator `+=` and `*=`:
390
390
391
391
```js run
392
392
let n = 2;
393
-
n += 5; // now n = 7 (same as n = n + 5)
394
-
n *= 2; // now n = 14 (same as n = n * 2)
393
+
n += 5; // sekarang n = 7 (sama dengan n = n + 5)
394
+
n *= 2; // sekarang n = 14 (sama dengan n = n * 2)
395
395
396
396
alert( n ); // 14
397
397
```
398
398
399
-
Short "modify-and-assign" operators exist for all arithmetical and bitwise operators:`/=`, `-=`, etc.
399
+
Operator pendek "modifikasi-dan-tetapkan" eksis untuk semua operator arimatika dan bitwise: `/=`, `-=`, dll.
400
400
401
-
Such operators have the same precedence as a normal assignment, so they run after most other calculations:
401
+
Operator macam ini punya presedensi yang sama dengan penetapan normal, jadi mereka berjalan setelah kebanyakan kalkulasi lain:
402
402
403
403
```js run
404
404
let n = 2;
405
405
406
406
n *= 3 + 5;
407
407
408
-
alert( n ); // 16 (right part evaluated first, same as n *= 8)
408
+
alert( n ); // 16 (bagian kanan dievaluasi lebih dulu, sama dengan n *= 8)
409
409
```
410
410
411
-
## Comma
411
+
## Koma
412
412
413
-
The comma operator `,`is one of the rarest and most unusual operators. Sometimes, it's used to write shorter code, so we need to know it in order to understand what's going on.
413
+
Operator koma `,` ialah satu dari banyak operator paling langka dan tak biasa. Kadang, ia digunakan untuk menulis kode lebih pendek, jadi kita harus tahu itu untuk memahami apa yang terjadi.
414
414
415
-
The comma operator allows us to evaluate several expressions, dividing them with a comma`,`. Eachof them is evaluated but only the result of the last one is returned.
415
+
Operator koma memperbolehkan untuk mengevaluasi beberapa expresi, membagi mereka dengan koma `,`. Each of them is evaluated but only the result of the last one is returned.
416
416
417
-
For example:
417
+
Misalnya:
418
418
419
419
```js run
420
420
*!*
421
421
let a = (1 + 2, 3 + 4);
422
422
*/!*
423
423
424
-
alert( a ); // 7 (the result of 3 + 4)
424
+
alert( a ); // 7 (hasil dari 3 + 4)
425
425
```
426
426
427
-
Here, the first expression `1 + 2`is evaluated and its result is thrown away. Then, `3 + 4`is evaluated and returned as the result.
427
+
Di sini, expresi pertama `1 + 2` dievaluasi dan hasilnya dibuang. Lalu, `3 + 4` dievaluasi dan dikembalikan sebagai hasilnya.
428
428
429
-
```smart header="Comma has a very low precedence"
430
-
Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above.
429
+
```smart header="Koma punya presedensi sangat kecil"
430
+
Harap ingat bahwa operator koma punya presedensi sangat kecil, lebih kecil dari `=`, jadi tanda kurung penting dalam contoh di atas.
431
431
432
-
Without them: `a =1+2, 3+4`evaluates`+`first, summing the numbers into `a =3, 7`, then the assignment operator `=`assigns`a =3`, and finally the number after the comma, `7`, is not processed so it's ignored.
432
+
Tanpa mereka: `a = 1 + 2, 3 + 4` mengevaluasi `+` terlebih dahulu, penjumlahan tersebut menjadi `a = 3, 7`, lalu operator penetapan `=` menetapkan `a = 3`, dan pada akhirnya angka setelah koma, `7`, tak diproses sehingga ia diabaikan.
433
433
```
434
434
435
-
Why do we need an operator that throws away everything except the last part?
435
+
Kenapa kita butuh operator yang membuang semuanya kecuali bagian akhirnya?
436
436
437
-
Sometimes, people use it in more complex constructs to put several actions in one line.
437
+
Kadang, orang memakai itu dalam konstruksi rumit untuk menaruh beberapa aksi dalam satu baris.
438
438
439
-
For example:
439
+
Misalnya:
440
440
441
441
```js
442
-
// three operations in one line
442
+
// tiga operasi dalam satu baris
443
443
for (*!*a = 1, b = 3, c = a * b*/!*; a < 10; a++) {
444
444
...
445
445
}
446
446
```
447
447
448
-
Such tricks are used in many JavaScript frameworks. That's why we're mentioning them. But, usually, they don't improve code readability so we should think well before using them.
448
+
Trik macam ini dipakai di banyak framework JavaScript. Itulah kenapa kita membahas mereka. Tapi, biasanya, mereka tak meningkatkan keterbacaan kode sehingga kita sebaiknya pikir-pikir dulu sebelum menggunakan mereka.
0 commit comments