func`string`
. 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).
+Grawisy umożliwia również określenie "funkcji szablonu" przed pierwszym grawisem. Składnia to: func`string`
. 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).
-## Special characters
+## Znaki specjalne
-It is still possible to create multiline strings with single and double quotes by using a so-called "newline character", written as `\n`, which denotes a line break:
+Ciągi wielowierszowe można również tworzyć za pomocą pojedynczych i podwójnych cudzysłowów, używając do tego tak zwanego "znaku nowej linii", który jest zapisany jako `\n`:
```js run
let guestList = "Guests:\n * John\n * Pete\n * Mary";
-alert(guestList); // a multiline list of guests
+alert(guestList); // wielowierszowa lista gości
```
-For example, these two lines are equal, just written differently:
+Te dwie linie są takie same, po prostu napisane inaczej:
```js run
-let str1 = "Hello\nWorld"; // two lines using a "newline symbol"
+let str1 = "Hello\nWorld"; // nowa linia ze "znaku nowej linii"
-// two lines using a normal newline and backticks
+// nowa linia utworzona przy pomocy grawisów
let str2 = `Hello
World`;
alert(str1 == str2); // true
```
-There are other, less common "special" characters.
+Istnieją inne rzadziej używane "znaki specjalne".
-Here's the full list:
+Oto pełna lista:
-| Character | Description |
+| Znak | Opis |
|-----------|-------------|
-|`\n`|New line|
-|`\r`|Carriage return: not used alone. Windows text files use a combination of two characters `\r\n` to represent a line break. |
-|`\'`, `\"`|Quotes|
-|`\\`|Backslash|
-|`\t`|Tab|
-|`\b`, `\f`, `\v`| Backspace, Form Feed, Vertical Tab -- kept for compatibility, not used nowadays. |
-|`\xXX`|Unicode character with the given hexadecimal unicode `XX`, e.g. `'\x7A'` is the same as `'z'`.|
-|`\uXXXX`|A unicode symbol with the hex code `XXXX` in UTF-16 encoding, for instance `\u00A9` -- is a unicode for the copyright symbol `©`. It must be exactly 4 hex digits. |
-|`\u{X…XXXXXX}` (1 to 6 hex characters)|A unicode symbol with the given UTF-32 encoding. Some rare characters are encoded with two unicode symbols, taking 4 bytes. This way we can insert long codes. |
+|`\n`|Nowa linia|
+|`\r`|Znak powrotu: nie używany samodzielnie. Pliki tekstowe Windows używają kombinacji dwóch znaków `\r\n` do reprezentowania łamania wiersza. |
+|`\'`, `\"`|Cudzysłów|
+|`\\`|Ukośnik wsteczny|
+|`\t`|Tabulacja|
+|`\b`, `\f`, `\v`| Backspace, Form Feed oraz Vertical Tab -- pozostawione do wstecznej kompatybilności, obecnie nieużywane. |
+|`\xXX`|Znak Unicode o podanym szesnastkowym kodzie`XX`, np. `'\x7A'` to to samo co `'z'`.|
+|`\uXXXX`|Znak Unicode z kodem szesnastkowym `XXXX` w kodowaniu UTF-16, np. `\u00A9` -- kod Unicode dla symbolu praw autorskich `©`. Musi mieć dokładnie 4 cyfry szesnastkowe. |
+|`\u{X…XXXXXX}` (od 1 do 6 znaków szesnastkowych)|Znak Unicode z podanym kodowaniem UTF-32. Niektóre rzadkie znaki są zakodowane za pomocą dwóch symboli Unicode, zajmując 4 bajty. W ten sposób możemy wstawiać długie kody. |
-Examples with unicode:
+Przykłady z Unicode:
```js run
alert( "\u00A9" ); // ©
-alert( "\u{20331}" ); // 佫, a rare Chinese hieroglyph (long unicode)
-alert( "\u{1F60D}" ); // 😍, a smiling face symbol (another long unicode)
+alert( "\u{20331}" ); // 佫, rzadki chiński znak (długi Unicode)
+alert( "\u{1F60D}" ); // 😍, symbol uśmiechniętej buźki (kolejny długi Unicode)
```
-All special characters start with a backslash character `\`. It is also called an "escape character".
+Wszystkie znaki specjalne zaczynają się od odwrotnego ukośnika `\`, tzw. "znak ucieczki".
-We might also use it if we wanted to insert a quote into the string.
+Możemy go również użyć, jeśli chcemy wstawić cytat do łańcucha.
-For instance:
+Na przykład:
```js run
alert( 'I*!*\'*/!*m the Walrus!' ); // *!*I'm*/!* the Walrus!
```
-As you can see, we have to prepend the inner quote by the backslash `\'`, because otherwise it would indicate the string end.
+Jak widać, wewnętrzny cytat musimy poprzedzić `\'`, ponieważ w przeciwnym razie oznaczałoby to koniec ciągu.
-Of course, only to the quotes that are the same as the enclosing ones need to be escaped. So, as a more elegant solution, we could switch to double quotes or backticks instead:
+Oczywiście wymóg użycia "znaku ucieczki" dotyczy tylko tych samych cudzysłowów budujących łańcuch. Możemy więc użyć bardziej eleganckiego rozwiązania, używając podwójnych cudzysłowów lub znaków wstecznych dla tego ciągu:
```js run
alert( `I'm the Walrus!` ); // I'm the Walrus!
```
-Note that the backslash `\` serves for the correct reading of the string by JavaScript, then disappears. The in-memory string has no `\`. You can clearly see that in `alert` from the examples above.
+Zauważ, że znak ucieczki `\` służy tylko do poprawnego odczytania wiersza przez JavaScript i nie jest dopisywany do wiersza. Łańcuch nie ma go w pamięci. Widać to wyraźnie w wywołaniu funkcji `alert` na powyższym przykładzie.
-But what if we need to show an actual backslash `\` within the string?
+Ale co, jeśli musimy pokazać wsteczny ukośnik `\` w łańcuchu?
-That's possible, but we need to double it like `\\`:
+To możliwe, ale musimy go podwoić `\\`:
```js run
alert( `The backslash: \\` ); // The backslash: \
```
-## String length
+## Długość łańcucha
-The `length` property has the string length:
+Właściwość `length` zawiera długość ciągu:
```js run
alert( `My\n`.length ); // 3
```
-Note that `\n` is a single "special" character, so the length is indeed `3`.
+Pamiętaj, że `\n` to pojedynczy "znak specjalny", więc długość łańcucha wynosi `3`.
-```warn header="`length` is a property"
-People with a background in some other languages sometimes mistype by calling `str.length()` instead of just `str.length`. That doesn't work.
+```warn header="`length` jest wartością"
+Zdarza się, że osoby z praktyką w innych językach przypadkowo dodają nawiasy `str.length()`, zamiast po prostu `str.length`. To nie zadziała.
-Please note that `str.length` is a numeric property, not a function. There is no need to add parenthesis after it.
+Należy pamiętać, że `str.length` jest właściwością numeryczną, a nie funkcją. Nie ma potrzeby dodawania po nim nawiasu.
```
-## Accessing characters
+## Dostęp do znaków
-To get a character at position `pos`, use square brackets `[pos]` or call the method [str.charAt(pos)](mdn:js/String/charAt). The first character starts from the zero position:
+Aby uzyskać znak w pozycji `pos`, użyj nawiasów kwadratowych `[pos]` lub wywołaj metodę [str.charAt(pos)](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/String/charAt). Pierwszy znak zaczyna się od pozycji zerowej:
```js run
let str = `Hello`;
-// the first character
+// zwraca pierwszy znak
alert( str[0] ); // H
alert( str.charAt(0) ); // H
-// the last character
+// zwraca ostatni znak
alert( str[str.length - 1] ); // o
```
-The square brackets are a modern way of getting a character, while `charAt` exists mostly for historical reasons.
+Nawiasy kwadratowe to nowoczesny sposób na uzyskanie znaku, natomiast `charAt` istnieje głównie ze względów historycznych.
-The only difference between them is that if no character is found, `[]` returns `undefined`, and `charAt` returns an empty string:
+Jedyna różnica między nimi polega na tym, że jeśli nie zostanie znaleziony żaden znak, `[]` zwraca `undefined`, a `charAt` zwraca pusty ciąg:
```js run
let str = `Hello`;
alert( str[1000] ); // undefined
-alert( str.charAt(1000) ); // '' (an empty string)
+alert( str.charAt(1000) ); // '' (pusty ciąg)
```
-We can also iterate over characters using `for..of`:
+Możemy również iterować po znakach, używając `for..of`:
```js run
for (let char of "Hello") {
- alert(char); // H,e,l,l,o (char becomes "H", then "e", then "l" etc)
+ alert(char); // H,e,l,l,o (char - najpierw "H", później "e", następnie "l" itd.)
}
```
-## Strings are immutable
+## Łańcuchy są niezmienne
-Strings can't be changed in JavaScript. It is impossible to change a character.
+Treść łańcucha w JavaScript nie może być zmieniona. Nie można wziąć znaku ze środka ciągu i zastąpić go innym.
-Let's try it to show that it doesn't work:
+Spróbujmy i zobaczmy, czy to nie działa:
```js run
let str = 'Hi';
str[0] = 'h'; // error
-alert( str[0] ); // doesn't work
+alert( str[0] ); // nie działa
```
-The usual workaround is to create a whole new string and assign it to `str` instead of the old one.
+Powszechnym obejściem tego problemu jest utworzenie zupełnie nowego łańcucha i przypisanie go do `str` zamiast starego.
-For instance:
+Na przykład:
```js run
let str = 'Hi';
-str = 'h' + str[1]; // replace the string
+str = 'h' + str[1]; // zamieniamy ciąg
alert( str ); // hi
```
-In the following sections we'll see more examples of this.
+Więcej przykładów zobaczymy w kolejnych sekcjach.
-## Changing the case
+## Zmiana wielkości znaków
-Methods [toLowerCase()](mdn:js/String/toLowerCase) and [toUpperCase()](mdn:js/String/toUpperCase) change the case:
+Metody [toLowerCase()](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase) i [toUpperCase()](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) zmieniają wielkość liter:
```js run
alert( 'Interface'.toUpperCase() ); // INTERFACE
alert( 'Interface'.toLowerCase() ); // interface
```
-Or, if we want a single character lowercased:
+Lub, jeśli chcemy, aby jeden znak był pisany małymi literami:
```js
alert( 'Interface'[0].toLowerCase() ); // 'i'
```
-## Searching for a substring
+## Wyszukiwanie podciągu
-There are multiple ways to look for a substring within a string.
+Istnieje wiele sposobów wyszukiwania podciągu w ciągu.
### str.indexOf
-The first method is [str.indexOf(substr, pos)](mdn:js/String/indexOf).
+Pierwszą metodą jest [str.indexOf(substr, pos)](mdn:js/String/indexOf).
-It looks for the `substr` in `str`, starting from the given position `pos`, and returns the position where the match was found or `-1` if nothing can be found.
+Szuka `substr` w `str`, zaczynając od podanej pozycji `pos`, i zwraca pozycję, w której znalazł dopasowanie lub `-1` jeśli nic nie zostało znalezione.
-For instance:
+Na przykład:
```js run
let str = 'Widget with id';
-alert( str.indexOf('Widget') ); // 0, because 'Widget' is found at the beginning
-alert( str.indexOf('widget') ); // -1, not found, the search is case-sensitive
+alert( str.indexOf('Widget') ); // 0, because 'Widget' został znaleziony na początku łańcucha
+alert( str.indexOf('widget') ); // -1, nie znaleziono, w wyszukiwaniu rozróżniana jest wielkość liter
-alert( str.indexOf("id") ); // 1, "id" is found at the position 1 (..idget with id)
+alert( str.indexOf("id") ); // 1, "id" znajduje się na pozycji 1 (id w Widget)
```
-The optional second parameter allows us to search starting from the given position.
+Opcjonalny drugi parametr pozwala nam na wyszukiwanie zaczynając od podanej pozycji.
-For instance, the first occurrence of `"id"` is at position `1`. To look for the next occurrence, let's start the search from position `2`:
+Na przykład pierwsze wystąpienie `"id"` występuje na pozycji `1`. Aby wyszukać następne wystąpienie, zacznijmy wyszukiwanie od pozycji `2`:
```js run
let str = 'Widget with id';
@@ -249,12 +247,12 @@ let str = 'Widget with id';
alert( str.indexOf('id', 2) ) // 12
```
-If we're interested in all occurrences, we can run `indexOf` in a loop. Every new call is made with the position after the previous match:
+Jeśli interesują nas wszystkie wystąpienia, możemy uruchomić `indexOf` w pętli. Każde nowe wywołanie jest wykonywane na następnej pozycji w łańcuchu po poprzednim dopasowaniu:
```js run
let str = 'As sly as a fox, as strong as an ox';
-let target = 'as'; // let's look for it
+let target = 'as'; // cel wyszukiwania
let pos = 0;
while (true) {
@@ -262,11 +260,11 @@ while (true) {
if (foundPos == -1) break;
alert( `Found at ${foundPos}` );
- pos = foundPos + 1; // continue the search from the next position
+ pos = foundPos + 1; // kontynuuj wyszukiwanie od następnej pozycji
}
```
-The same algorithm can be layed out shorter:
+Ten sam algorytm można skrócić:
```js run
let str = "As sly as a fox, as strong as an ox";
@@ -281,24 +279,24 @@ while ((pos = str.indexOf(target, pos + 1)) != -1) {
```
```smart header="`str.lastIndexOf(substr, position)`"
-There is also a similar method [str.lastIndexOf(substr, position)](mdn:js/String/lastIndexOf) that searches from the end of a string to its beginning.
+Istnieje również podobna metoda [str.lastIndexOf(substr, position)](mdn:js/String/lastIndexOf), która przeszukuje string od końca do jego początku.
-It would list the occurrences in the reverse order.
+Zwraca wystąpienia w odwrotnej kolejności.
```
-There is a slight inconvenience with `indexOf` in the `if` test. We can't put it in the `if` like this:
+Istnieje niewielka niedogodność z metodą `indexOf` w sprawdzeniu warunkowym `if`. Ten warunek nie zadziała prawidłowo:
```js run
let str = "Widget with id";
if (str.indexOf("Widget")) {
- alert("We found it"); // doesn't work!
+ alert("We found it"); // Nie zadziała!
}
```
-The `alert` in the example above doesn't show because `str.indexOf("Widget")` returns `0` (meaning that it found the match at the starting position). Right, but `if` considers `0` to be `false`.
+`alert` w powyższym przykładzie nie jest wyświetlany, ponieważ `str.indexOf("Widget")` zwraca `0` (co oznacza, że znalazł dopasowanie na pozycji wyjściowej). Natomiast warunek `if` odczytuje `0` jako `false`.
-So, we should actually check for `-1`, like this:
+Dlatego też powinniśmy użyć warunku dla wartości `-1`:
```js run
let str = "Widget with id";
@@ -306,54 +304,54 @@ let str = "Widget with id";
*!*
if (str.indexOf("Widget") != -1) {
*/!*
- alert("We found it"); // works now!
+ alert("We found it"); // Działa!
}
```
-#### The bitwise NOT trick
+#### Trik bitowy NOT
-One of the old tricks used here is the [bitwise NOT](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT) `~` operator. It converts the number to a 32-bit integer (removes the decimal part if exists) and then reverses all bits in its binary representation.
+Istnieje stara sztuczka z użyciem [bitowego operatora NOT](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT) `~`. Konwertuje liczbę na 32-bitową liczbę całkowitą (usuwa część dziesiętną, jeśli istnieje), a następnie odwraca wszystkie bity w reprezentacji binarnej.
-In practice, that means a simple thing: for 32-bit integers `~n` equals `-(n+1)`.
+W praktyce oznacza to, że: dla 32-bitowych liczb całkowitych `~n` równa się `-(n+1)`.
-For instance:
+Na przykład:
```js run
-alert( ~2 ); // -3, the same as -(2+1)
-alert( ~1 ); // -2, the same as -(1+1)
-alert( ~0 ); // -1, the same as -(0+1)
+alert( ~2 ); // -3, to samo, co -(2+1)
+alert( ~1 ); // -2, to samo, co -(1+1)
+alert( ~0 ); // -1, to samo, co -(0+1)
*!*
-alert( ~-1 ); // 0, the same as -(-1+1)
+alert( ~-1 ); // 0, to samo, co -(-1+1)
*/!*
```
-As we can see, `~n` is zero only if `n == -1` (that's for any 32-bit signed integer `n`).
+Zatem `~n` jest równe zeru, tylko, gdy `n == -1` (dowolna 32-bitowa liczby całkowitej ze znakiem `n`).
-So, the test `if ( ~str.indexOf("...") )` is truthy only if the result of `indexOf` is not `-1`. In other words, when there is a match.
+Tak więc warunek `if ( ~str.indexOf("...") )` jest prawdziwy tylko wtedy, gdy wynikiem `indexOf` nie jest `-1`. Innymi słowy, kiedy jest dopasowanie.
-People use it to shorten `indexOf` checks:
+Ludzie używają go do skrócenia `indexOf`:
```js run
let str = "Widget";
if (~str.indexOf("Widget")) {
- alert( 'Found it!' ); // works
+ alert( 'Found it!' ); // działa
}
```
-It is usually not recommended to use language features in a non-obvious way, but this particular trick is widely used in old code, so we should understand it.
+Generalnie odradza się używanie funkcji językowych w jakikolwiek nieoczywisty sposób, ale ta sztuczka jest szeroko stosowana w starszym kodzie, więc ważne jest, aby ją zrozumieć.
-Just remember: `if (~str.indexOf(...))` reads as "if found".
+Wystarczy, że zapamiętasz: `if (~str.indexOf(...))` oznacza "jeśli znaleziono".
-To be precise though, as big numbers are truncated to 32 bits by `~` operator, there exist other numbers that give `0`, the smallest is `~4294967295=0`. That makes such check is correct only if a string is not that long.
+Aby być precyzyjnym, należy wspomnieć, że z powodu iż, duże liczby są obcinane przez operator `~` do 32 bitów, istnieją inne liczby, które dają 0. Najmniejsza to `~4294967295=0`. To sprawia, że takie sprawdzenie jest poprawne tylko wtedy, gdy łańcuch nie jest tak długi.
-Right now we can see this trick only in the old code, as modern JavaScript provides `.includes` method (see below).
+Aktualnie tę sztuczkę możemy zobaczyć tylko w starym kodzie, ponieważ współczesny JavaScript zapewnia metodę .includes (patrz poniżej).
### includes, startsWith, endsWith
-The more modern method [str.includes(substr, pos)](mdn:js/String/includes) returns `true/false` depending on whether `str` contains `substr` within.
+Bardziej nowoczesna metoda [str.includes(substr, pos)](mdn:js/String/includes) zwraca `true/false` w zależności, czy `str` zawiera w sobie `substr`.
-It's the right choice if we need to test for the match, but don't need its position:
+To właściwy wybór, jeśli musimy sprawdzić wystąpienie jakiegoś podciągu, ale nie interesuje nas jego pozycja w łańcuchu:
```js run
alert( "Widget with id".includes("Widget") ); // true
@@ -361,152 +359,152 @@ alert( "Widget with id".includes("Widget") ); // true
alert( "Hello".includes("Bye") ); // false
```
-The optional second argument of `str.includes` is the position to start searching from:
+Opcjonalny drugi argument `str.includes` to pozycja, od której należy rozpocząć wyszukiwanie:
```js run
alert( "Widget".includes("id") ); // true
-alert( "Widget".includes("id", 3) ); // false, from position 3 there is no "id"
+alert( "Widget".includes("id", 3) ); // false, od pozycji 3 "id nie występuje
```
-The methods [str.startsWith](mdn:js/String/startsWith) and [str.endsWith](mdn:js/String/endsWith) do exactly what they say:
+Metody [str.startsWith](mdn:js/String/startsWith) i [str.endsWith](mdn:js/String/endsWith) sprawdzają odpowiednio, czy łańcuch zaczyna się i kończy na określonym podciągu:
```js run
-alert( "Widget".startsWith("Wid") ); // true, "Widget" starts with "Wid"
-alert( "Widget".endsWith("get") ); // true, "Widget" ends with "get"
+alert( "Widget".startsWith("Wid") ); // true, "Widget" zaczyna się od "Wid"
+alert( "Widget".endsWith("get") ); // true, "Widget" kończy się na "get"
```
-## Getting a substring
+## Pobieranie podciągu
-There are 3 methods in JavaScript to get a substring: `substring`, `substr` and `slice`.
+JavaScript ma 3 metody uzyskiwania podciągu: `substring`, `substr` i `slice`.
`str.slice(start [, end])`
-: Returns the part of the string from `start` to (but not including) `end`.
+: Zwraca część łańcucha od `start` do `end` (ale go nie uwzględnia).
- For instance:
+ Na przykład:
```js run
let str = "stringify";
- alert( str.slice(0, 5) ); // 'strin', the substring from 0 to 5 (not including 5)
- alert( str.slice(0, 1) ); // 's', from 0 to 1, but not including 1, so only character at 0
+ alert( str.slice(0, 5) ); // 'strin', podciąg od 0 do 5 (nie uwzględnia 5)
+ alert( str.slice(0, 1) ); // 's', od 0 do 1, ale nie uwzględnia 1, czyli tylko jeden znak z pozycji 0
```
- If there is no second argument, then `slice` goes till the end of the string:
+ Jeśli nie ma drugiego argumentu, `slice` zwraca znaki do końca linii:
```js run
let str = "st*!*ringify*/!*";
- alert( str.slice(2) ); // 'ringify', from the 2nd position till the end
+ alert( str.slice(2) ); // 'ringify', od drugiej pozycji do końca
```
- Negative values for `start/end` are also possible. They mean the position is counted from the string end:
+ Możliwe są również ujemne wartości `start/end`. Oznacza to, że pozycja jest liczona od końca ciągu:
```js run
let str = "strin*!*gif*/!*y";
- // start at the 4th position from the right, end at the 1st from the right
+ // zaczynamy od pozycji 4 od prawej i kończymy na pozycji 1 od prawej
alert( str.slice(-4, -1) ); // 'gif'
```
`str.substring(start [, end])`
-: Returns the part of the string *between* `start` and `end`.
+: Zwraca część ciągu _pomiędzy_ `start` i `end`.
- This is almost the same as `slice`, but it allows `start` to be greater than `end`.
+ Jest to prawie to samo, co `slice`, z tą różnicą, że `start` może być większe niż `end`.
- For instance:
+ Na przykład:
```js run
let str = "st*!*ring*/!*ify";
- // these are same for substring
+ // dla substring te dwa przykłady są takie same
alert( str.substring(2, 6) ); // "ring"
alert( str.substring(6, 2) ); // "ring"
- // ...but not for slice:
- alert( str.slice(2, 6) ); // "ring" (the same)
- alert( str.slice(6, 2) ); // "" (an empty string)
+ // ...ale nie dla slice:
+ alert( str.slice(2, 6) ); // "ring" (to samo)
+ alert( str.slice(6, 2) ); // "" (pusty łańcuch)
```
- Negative arguments are (unlike slice) not supported, they are treated as `0`.
+ `substring` w przeciwieństwie do `slice` nie obsługuje wartości ujemnych i interpretuje je jako `0`.
`str.substr(start [, length])`
-: Returns the part of the string from `start`, with the given `length`.
+: Zwraca część ciągu od `start` do podanej długości `length`.
- In contrast with the previous methods, this one allows us to specify the `length` instead of the ending position:
+ W przeciwieństwie do poprzednich metod, ta umożliwia określenie długości `length` zamiast pozycji końcowej:
```js run
let str = "st*!*ring*/!*ify";
- alert( str.substr(2, 4) ); // 'ring', from the 2nd position get 4 characters
+ alert( str.substr(2, 4) ); // 'ring', 4 znaki liczone od drugiej pozycji
```
- The first argument may be negative, to count from the end:
+ Wartość pierwszego argumentu może być ujemna, w takim przypadku pozycja określana jest od końca:
```js run
let str = "strin*!*gi*/!*fy";
- alert( str.substr(-4, 2) ); // 'gi', from the 4th position get 2 characters
+ alert( str.substr(-4, 2) ); // 'gi', 2 znaki liczone od czwartej pozycji od końca
```
-Let's recap these methods to avoid any confusion:
+Podsumujmy te metody, aby uniknąć nieporozumień:
-| method | selects... | negatives |
+| metoda | wybiera... | wartości ujemne |
|--------|-----------|-----------|
-| `slice(start, end)` | from `start` to `end` (not including `end`) | allows negatives |
-| `substring(start, end)` | between `start` and `end` | negative values mean `0` |
-| `substr(start, length)` | from `start` get `length` characters | allows negative `start` |
+| `slice(start, end)` | od `start` do `end` (bez uwzględnienia `end`) | zezwala |
+| `substring(start, end)` | pomiędzy `start` i `end` | wartości ujemne oznaczają `0` |
+| `substr(start, length)` | `length` znaków od `start` | pozwala na wartość ujemną dla `start` |
-```smart header="Which one to choose?"
-All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere.
+```smart header="Którą metodę wybrać?"
+Wszystkie metody robią robotę. Formalnie `substr` ma niewielką wadę: nie jest opisana w podstawowej specyfikacji JavaScript, ale w załączniku B. Dodatek ten opisuje cechy języka używanego w przeglądarkach, które istnieją głównie ze względów historycznych. Dlatego środowiska inne niż przeglądarki mogą go nie obsługiwać. Jednak w praktyce działa wszędzie.
-Of the other two variants, `slice` is a little bit more flexible, it allows negative arguments and shorter to write. So, it's enough to remember solely `slice` of these three methods.
+Z pozostałych dwóch opcji, `slice` jest nieco bardziej elastyczne - pozwala na użycie wartości ujemny i jest krótsze. Wystarczy więc, że spośród tych metoda zapamiętasz `slice`.
```
-## Comparing strings
+## Porównywanie łańcuchów
-As we know from the chapter Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: