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/05-data-types/03-string/article.md
+12-14Lines changed: 12 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
# Strings
1
+
# Łańcuchy
2
2
3
-
In JavaScript, the textual data is stored as strings. There is no separate type for a single character.
3
+
W JavaScript dane tekstowe są przechowywane jako łańcuchy (ciągi znaków). Nie ma oddzielnego typu dla pojedynczego znaku.
4
4
5
-
The internal format for strings is always [UTF-16](https://en.wikipedia.org/wiki/UTF-16), it is not tied to the page encoding.
5
+
Wewnętrzny format ciągów to zawsze [UTF-16](https://pl.wikipedia.org/wiki/UTF-16), nie jest on powiązany z kodowaniem strony
6
6
7
-
## Quotes
7
+
## Cytaty
8
8
9
-
Let's recall the kinds of quotes.
9
+
W JavaScript istnieją różne rodzaje cudzysłowów.
10
10
11
-
Strings can be enclosed within either single quotes, double quotes or backticks:
11
+
Ciąg można utworzyć za pomocą cudzysłowów pojedynczych, podwójnych lub grawisów:
12
12
13
13
```js
14
14
let single ='single-quoted';
@@ -17,7 +17,7 @@ let double = "double-quoted";
17
17
let backticks =`backticks`;
18
18
```
19
19
20
-
Single and double quotes are essentially the same. Backticks, however, allow us to embed any expression into the string, by wrapping it in`${…}`:
20
+
Pojedyncze i podwójne cudzysłowy są zasadniczo takie same. Grawisy natomiast pozwalają nam osadzić dowolne wyrażenie w łańcuchu, owijając je w`${…}`:
21
21
22
22
```js run
23
23
functionsum(a, b) {
@@ -27,7 +27,7 @@ function sum(a, b) {
27
27
alert(`1 + 2 = ${sum(1, 2)}.`); // 1 + 2 = 3.
28
28
```
29
29
30
-
Another advantage of using backticks is that they allow a string to span multiple lines:
30
+
Kolejną zaletą grawisów jest to, że mogą obejmować więcej niż jedną linię, na przykład:
31
31
32
32
```js run
33
33
let guestList =`Guests:
@@ -36,21 +36,19 @@ let guestList = `Guests:
36
36
* Mary
37
37
`;
38
38
39
-
alert(guestList); //a list of guests, multiple lines
39
+
alert(guestList); //lista gości, wiele wierszy
40
40
```
41
41
42
-
Looks natural, right? But single or double quotes do not work this way.
43
-
44
-
If we use them and try to use multiple lines, there'll be an error:
42
+
Wygląda całkiem naturalnie, prawda? Jeśli jednak spróbujesz użyć pojedynczych lub podwójnych cudzysłowów w ten sam sposób, wystąpi błąd:
45
43
46
44
```js run
47
45
let guestList ="Guests: // Error: Unexpected token ILLEGAL
48
46
* John";
49
47
```
50
48
51
-
Single and double quotes come from ancient times of language creation when the need for multiline strings was not taken into account. Backticks appeared much later and thus are more versatile.
49
+
Pojedyncze i podwójne cudzysłowy pochodzą ze starożytnych czasów tworzenia języka, kiedy nie brano pod uwagę potrzeby wielowierszowych ciągów. Grawisy pojawiły się znacznie później i dzięki temu są bardziej wszechstronne.
52
50
53
-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func`string`</code>. The function `func`is called automatically, receives the string and embedded expressions and can process them. This is called "tagged templates". This feature makes it easier to implement custom templating, but is rarely used in practice. You can read more about it in the [manual](mdn:/JavaScript/Reference/Template_literals#Tagged_templates).
51
+
Grawisy umożliwia również określenie "funkcji szablonu" przed pierwszym grawisem. Składnia to: <code>func`string`</code>. Automatycznie wywoływana funkcja `func`pobiera osadzony w niej ciąg znaków i wyrażenia i może je przetwarzać. Nazywa się to „otagowanymi szablonami”. Ta funkcjonalność ułatwia implementację niestandardowych szablonów, ale jest rzadko używana w praktyce. Więcej na ten temat przeczytasz w [dokumentacji](mdn:/JavaScript/Reference/Template_literals#Tagged_templates).
0 commit comments