Skip to content

Commit 37f9093

Browse files
Bartłomiej Kalembasculpt0r
Bartłomiej Kalemba
authored andcommitted
WIP: translated half of article
1 parent 1545116 commit 37f9093

File tree

1 file changed

+16
-16
lines changed
  • 1-js/02-first-steps/12-nullish-coalescing-operator

1 file changed

+16
-16
lines changed

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# Nullish coalescing operator '??'
1+
# Operator łączenia wartości null '??'
22

33
[recent browser="new"]
44

5-
Here, in this article, we'll say that an expression is "defined" when it's neither `null` nor `undefined`.
5+
W tym artykule zakładamy, że wyrażenie jest "zdefiniowane", jeżeli nie jest `null` albo `undefined`.
66

7-
The nullish coalescing operator is written as two question marks `??`.
7+
Operator łączenia wartości null zapisujemy jako dwa znaki zapytania `??`.
88

9-
The result of `a ?? b` is:
10-
- if `a` is defined, then `a`,
11-
- if `a` isn't defined, then `b`.
9+
Wynikiem `a ?? b` jest:
10+
- jeżeli `a` jest zdefiniowane, to wynikiem jest `a`,
11+
- jeżeli `a` nie jest zdefiniowane, to wynikiem jest `b`.
1212

1313

14-
In other words, `??` returns the first argument if it's not `null/undefined`. Otherwise, the second one.
14+
Innymi słowy, `??` zwraca pierwszy argument jeżeli jego wartość jest inna niż `null/undefined`. W przeciwnym razie, zwraca drugi argument.
1515

16-
The nullish coalescing operator isn't anything completely new. It's just a nice syntax to get the first "defined" value of the two.
16+
Operator łączenia wartości null isn't anything completely new. It's just a nice syntax to get the first "defined" value of the two.
1717

18-
We can rewrite `result = a ?? b` using the operators that we already know, like this:
18+
Możemy zapisać `result = a ?? b` używając operatorów, które już znamy:
1919

2020
```js
2121
result = (a !== null && a !== undefined) ? a : b;
2222
```
2323

24-
The common use case for `??` is to provide a default value for a potentially undefined variable.
24+
Typowym przykładem użycia `??` jest dostarczenie domyślnej wartości dla potencjalnie niezdefiniowanej zmiennej.
2525

26-
For example, here we show `Anonymous` if `user` isn't defined:
26+
Dla przykładu, wyświetlamy `Anonimowy`, jeżeli zmienna `user` jest niezdefiniowana:
2727

2828
```js run
2929
let user;
3030

31-
alert(user ?? "Anonymous"); // Anonymous
31+
alert(user ?? "Anonimowy"); // Anonimowy
3232
```
3333
34-
Of course, if `user` had any value except `null/undefined`, then we would see it instead:
34+
Oczywiście, jeżeli zmienna `user` ma inną wartość niż `null/undefined`, wtedy oczywiście powinniśmy zobaczyć jej wartość:
3535
3636
```js run
3737
let user = "John";
3838

39-
alert(user ?? "Anonymous"); // John
39+
alert(user ?? "Anonimowy"); // John
4040
```
4141
4242
We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
@@ -77,7 +77,7 @@ alert(firstName || lastName || nickName || "Anonymous"); // Supercoder
7777
7878
The OR `||` operator exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
7979
80-
On the other hand, the nullish coalescing operator `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
80+
On the other hand, Operator łączenia wartości null `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
8181
8282
The important difference between them is that:
8383
- `||` returns the first *truthy* value.
@@ -153,7 +153,7 @@ alert(x); // 2
153153
154154
## Summary
155155
156-
- The nullish coalescing operator `??` provides a short way to choose the first "defined" value from a list.
156+
- Operator łączenia wartości null `??` provides a short way to choose the first "defined" value from a list.
157157
158158
It's used to assign default values to variables:
159159

0 commit comments

Comments
 (0)